fork download
  1. #include<stdio.h>
  2. #include<algorithm>
  3. int main(){
  4. int n,*t;
  5. scanf("%d",&n);
  6. t=(int*)malloc(n*sizeof(int));
  7. for(int i=0;i<n;i++) scanf("%d",t+i);
  8. int k,cost=0,count=(t[n-2]>0?0:1);
  9. for(int i=n-3;i>=1;--i,k=0){
  10. if((t[i]>0?0:1)+count<(t[i]<0?0:1)+cost) k=1;
  11. count+=(t[i]>0?0:1);
  12. if(k) cost=(t[i]>0?0:1)+count;
  13. else cost+=(t[i]<0?0:1);
  14. }
  15. cost+=(t[0]>=0?1:0);
  16. cost+=(t[n-1]<=0?1:0);
  17. printf("%d\n",cost);
  18. return 0;
  19. }
Success #stdin #stdout 0s 3432KB
stdin
5
0 -1 1 2 -5
stdout
2