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 n,v[5005];
int dp[505][505][505],mn[505][505];
int main()
{
cin>>n;
for(int i=1; i<=n; i++) cin>>v[i];
int ans=0;
for(int i=2; i<=n; i++)
{
for(int j=i-1; j>=1; j--)
{
int st=j+1,dr=j;
long long a=v[st],b=v[dr];
int nr=0;
dp[i][j][j-1]=mn[j][j-1];
mn[i][j]=dp[i][j][j-1];
while( st<=i&&dr>=1 )
{
if(st==i&&dr==1) break;
if(st==i) dr--,b+=v[dr];
else if(dr==1) st++,a+=v[st];
else
{
if(a==b) nr++,st++,dr--,a+=v[st],b+=v[dr];
else if(a<b) st++,a+=v[st];
else dr--,b+=v[dr];
}
dp[i][j][dr-1]=max(dp[i][j][dr-1],nr+mn[j][dr-1]);
mn[i][j]=max(mn[i][j],dp[i][j][dr-1]);
}
ans=max(ans,mn[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... |