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;
const int MAX_N = 5e5 + 5;
long long A[MAX_N], pos[MAX_N], dp[MAX_N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> A[i];
A[i] += A[i - 1];
}
for (int i = 1; i <= N; i++) {
pos[i] = max(pos[i - 1], pos[i]);
dp[i] = dp[pos[i]] + 1;
int l = i, r = N, nxt = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (A[mid] - A[i] >= A[i] - A[pos[i]]) r = mid - 1, nxt = mid;
else l = mid + 1;
}
pos[nxt] = i;
}
cout << dp[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... |