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 N = 505;
typedef long long ll;
int n, a[N], dp[N][N];
ll pre[N];
int main(){
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
pre[0] = a[0];
for (int i = 1; i < n; ++i) pre[i] = a[i] + pre[i - 1];
for (int i = 0; i < n; ++i) {
dp[0][i] = 1;
}
for (int i = 1; i < n; ++i) {
for (int j = i; j < n; ++j) {
for (int k = 0; k < i; ++k) {
if (pre[j] - pre[i - 1] >= pre[i - 1] - (k ? pre[k - 1] : 0)) dp[i][j] = max(dp[i][j], dp[k][i - 1] + 1);
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) ans = max(ans, dp[i][n - 1]);
cout << ans << "\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... |