Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<algorithm>
- #include<iostream>
- #include<fstream>
- #include<cstring>
- #include<cstdio>
- #include<cmath>
- using namespace std;
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- const int N = 111111;
- int sum[N];
- int main()
- {
- int n, i, j, ans, t, zero;
- while(fin >> n)
- {
- zero = sum[0] = 0;
- j = 1;
- for(i = 1; i <= n; i ++)
- {
- fin >> t;
- if(t < 0) sum[j] = sum[j - 1] + 1, j ++;
- else if(t == 0) zero ++;
- else sum[j] = sum[j - 1], j ++;
- }
- if(j > 1)ans = 1 - sum[1] + sum[j - 1] - sum[1];
- else ans = 0;
- for(i = 2; i < j - 1; i ++)
- {
- ans = min(ans, sum[j - 1] + i - 2 * sum[i]);
- }
- fout << ans + zero << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement