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;
#define ll long long
#define ar array
const int mxN=5000;
int n, a[mxN], dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i)
cin >> a[i];
for (int i=0; i<n; ++i) {
for (int j=i-1; ~j; --j)
dp[i][j]=max(dp[i][j], dp[i][j+1]);
for (int j=0; j<=i; ++j) { // current seg [i-j, i] -> [i+1, something]
int cur=dp[i][j], ind=i, left=a[i];
for (int k=i+1; k<n; ++k) {
left-=a[k];
while(ind>i-j&&left<=0) {
cur+=left==0;
left+=a[--ind];
}
dp[k][k-i-1]=max(dp[k][k-i-1], cur-(left==a[ind]));
}
//cout << i << " " << j << " " << dp[i][j] << endl;
}
}
cout << *max_element(dp[n-1], dp[n-1]+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... |