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 <algorithm>
#include <vector>
using namespace std;
typedef long long llong;
int n;
llong S[500001];
int M[500002];
int D[500001];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> S[i];
S[i] += S[i - 1];
}
for (int i = 1; i <= n; ++i) {
M[i] = max(M[i], M[i - 1]);
D[i] = D[M[i]] + 1;
llong V = (S[i] << 1) - S[M[i]];
int s = i + 1, e = n + 1;
while (s < e) {
int m = (s + e) / 2;
if (V <= S[m]) e = m;
else s = m + 1;
}
M[s] = max(M[s], i);
}
printf("%d\n", D[n]);
return 0;
}
# | 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... |