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>
#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const int N = 1e6 + 1;
int n, res;
int a[N];
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<vi> dp(n + 1, vi(n + 1, -1e9));
for (int i = 1; i <= n; i++) dp[0][i] = 1;
vector<ll> pre(n + 1, 0);
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
for (int k = 0; k <= j; k++) {
int sum2 = pre[i] - pre[j];
int sum1 = pre[j] - pre[k];
if (sum1 <= sum2 && dp[k][j] > 0) {
dp[j][i] = max(dp[j][i], dp[k][j] + 1);
}
}
}
}
int res = 0;
for (int i = 0; i <= n; i++) res = max(res, dp[i][n]);
cout << res;
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... |