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;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long arr[n],dp[n][n];
for(int i=0; i<n; i++) cin >> arr[i];
memset(dp,0,sizeof(dp));
long long ans=0;
for(int i=1; i<n; i++){
long long pref[n];
pref[0]=dp[0][i-1];
for(int j=1; j<i; j++) pref[j]=max(pref[j-1],dp[j][i-1]);
int c=i-1,be=0;
long long len=0,len2=0;
for(int j=i; j<n; j++){
len+=arr[j];
while(len2<len&&c>=0){
len2+=arr[c];
c--;
}
if(c>0) dp[i][j]=pref[c-1]+be;
if(len2==len) be++;
}
long long best=0;
len=0; len2=0; c=i-1; be=0;
for(int j=i; j<n; j++){
len+=arr[j];
while(len2<len&&c>=0){
len2+=arr[c];
best=max(best,dp[c][i-1]+be);
c--;
}
if(len==len2) be++;
dp[i][j]=max(dp[i][j],best);
ans=max(ans,dp[i][j]);
}
}
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... |