This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<int> v(M), cum(M+1, 0);
for (int m = 0; m < M; ++m) {
cin >> v[m];
if (v[m] == 0) v[m] = -1;
cum[m+1] = cum[m]+v[m];
}
int mxpos = M;
int best = INF;
for (int m = M; m > 0; --m) {
int cur = (M-mxpos)+(cum[M]-cum[mxpos]) + (mxpos-m)-(cum[mxpos]-cum[m]) + m + cum[m];
best = min(best, cur);
}
cout << best << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |