Advertisement
Infiniti_Inter

Untitled

Mar 20th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1.  
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<fstream>
  5. #include<cstring>
  6. #include<cstdio>
  7. #include<cmath>
  8.  
  9. using namespace std;
  10.  
  11. ifstream fin("input.txt");
  12. ofstream fout("output.txt");
  13.  
  14. const int N = 111111;
  15.  
  16. int sum[N];
  17.  
  18. int main()
  19. {
  20. int n, i, j, ans, t, zero;
  21. while(fin >> n)
  22. {
  23. zero = sum[0] = 0;
  24. j = 1;
  25. for(i = 1; i <= n; i ++)
  26. {
  27. fin >> t;
  28. if(t < 0) sum[j] = sum[j - 1] + 1, j ++;
  29. else if(t == 0) zero ++;
  30. else sum[j] = sum[j - 1], j ++;
  31. }
  32. if(j > 1)ans = 1 - sum[1] + sum[j - 1] - sum[1];
  33. else ans = 0;
  34. for(i = 2; i < j - 1; i ++)
  35. {
  36. ans = min(ans, sum[j - 1] + i - 2 * sum[i]);
  37. }
  38. fout << ans + zero << endl;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement