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 = 3005;
const long long INF = 1e18 + 7;
long long A[MAX_N], dp[MAX_N][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];
}
int ans = 1;
for (int i = 1; i <= N; i++) dp[i][0] = INF;
for (int i = 1; i <= N; i++) dp[1][i] = A[i];
for (int s = 2; s <= N; s++) {
for (int i = 1, j = 1; i <= N; i++) {
while (j <= i and (dp[s - 1][j] == INF or dp[s - 1][j] <= A[i] - A[j])) j++;
dp[s][i] = INF;
if (dp[s - 1][j - 1] <= A[i] - A[j - 1]) dp[s][i] = A[i] - A[j - 1];
}
if (dp[s][N] == INF) break;
ans = s;
}
cout << ans;
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... |