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<cstdio>
long long a,t,m,i,z[2002],D[2002][2002];
long long max(long long A,long long B)
{
return A>B?A:B;
}
long long mod(long long X)
{
return (X+a)%a;
}
long long f(long long x,long long y,long long cnt)
{
if(cnt==0)return 0;
if(D[x][y])return D[x][y];
if((a-cnt)%2==1)
{
if(z[x]>z[y])return D[x][y]=f(mod(x-1),y,cnt-1);
else return D[x][y]=f(x,mod(y+1),cnt-1);
}
else
{
return D[x][y]=max(z[x]+f(mod(x-1),y,cnt-1),z[y]+f(x,mod(y+1),cnt-1));
}
}
main()
{
scanf("%lld",&a);
for(i=0;i<a;i++)
{
scanf("%lld",&z[i]);
}
for(i=0;i<a;i++)
{
t=z[i]+f(mod(i-1),mod(i+1),a-1);
printf("%lld ",t);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |