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 MXN = 5005;
int dp[MXN][MXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
int arr[N];
for(int i=0;i<N;i++) cin >> arr[i];
int res = 0;
for(int i=1;i<N;i++){
int pref[i];
pref[0] = dp[0][i-1];
for(int j=1;j<i;j++) pref[j] = max(pref[j-1],dp[j][i-1]);
int l=0,r=0,lst=i-1,cost=0;
for(int j=i,k=i-1;j<N;j++){
if(lst >= 0) dp[i][j] = pref[lst] + cost;
l += arr[j];
if(k >= 0 && r+arr[k] <= l) r += arr[k--];
if(l == r){
cost++,lst=k+1;
if(k >= 0) r += arr[k--];
lst--;
}
}
for(int j=i+1;j<N;j++) dp[i][j] = max(dp[i][j-1],dp[i][j]);
for(int j=0;j<N;j++) res = max(res,dp[i][j]);
}
cout << res << '\n';
}
# | 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... |