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>
#define all(s) s.begin(),s.end()
#define F first
#define S second
using namespace std;
typedef int ll;
ll n,a[5009],dp[509][509],p[5009],ans;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(ll i=1; i<=n; i++)
{
cin>>a[i];
p[i]=p[i-1]+a[i];
}
for(ll j=2; j<=n; j++)
{
for(ll i=2; i<=j; i++)
{
ll sum=0,l=i;
dp[i][j]=dp[i-1][i-1];
for(ll k=i-2; k; k--)
{
while((p[l]-p[i-1]<p[i-1]-p[k])&&(l<j-1))
l++;
if((p[l]-p[i-1]==p[i-1]-p[k])&&(p[l]-p[i-1]))
sum++;
dp[i][j]=max(dp[i][j],dp[k][i-1]+sum);
}
}
}
for(ll i=1; i<=n; i++)
ans=max(ans,dp[i][n]);
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... |