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>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
void testCase() {
int n;
cin >> n;
vector<long long> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
vector<int> dp(n + 1), to(n + 1);
to[1] = 0;
for (int i = 1; i <= n; i++) {
dp[i] = dp[to[i]] + 1;
int it = lower_bound(a.begin(), a.end(), 2 * a[i] - a[to[i]]) - a.begin();
if (it != n + 1) to[it] = i;
if (i < n) to[i + 1] = max(to[i + 1], to[i]);
}
cout << dp[n] << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
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... |