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>
#include<algorithm>
#include<vector>
#include<cmath>
long long a,i,j,m,M,dp[1000006],x[1000006],p[1000006],b[1000006];
main()
{
scanf("%lld",&a);
for(i=1;i<=a;i++)scanf("%lld",&x[i]);
for(i=1;i<=a;i++)p[i]=p[i-1]+i*x[i],b[i]=b[i-1]+x[i];
dp[0]=0;
for(i=1;i<=a+1;i++)
{
M=-1e18;
for(j=i-1;j>=0;j--)
{
M=std::max(M,dp[j]-j*(b[i-1]-b[j])-p[j]);
}
dp[i]=M+p[i-1];
m=std::max(dp[i],m);
}
printf("%lld",m);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |