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<bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef pair <int, int> pi;
const int MAXN = 500005;
int n;
llint a[MAXN], sum[MAXN], best[MAXN], sol[MAXN], mx[MAXN];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = a[i] + sum[i - 1];
}
for (int i = 1; i <= n; i++) {
mx[i] = max(mx[i], mx[i - 1]);
sol[i] = 1 + sol[mx[i]];
best[i] = sum[i] - sum[mx[i]];
int ind = lower_bound(sum, sum + n + 1, best[i] + sum[i]) - sum;
mx[ind] = max(mx[ind], (llint) i);
}
cout << sol[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... |