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>
#define N 1000001
#define M 1001
int n,a[M];
long long s[N],q,mx[M],t[M][M];
int main ()
{
int i,j;
long long as;
scanf ("%d",&n);
for (i=1;i<=n;i++)
scanf ("%d",a+i),s[i]=s[i-1]+a[i];
for (i=1;i<=n;i++)
for (j=i;j<=n;j++)
t[i][j]=t[i][j-1]+a[j]*(j-i+1);
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (mx[i]<t[j][i])
mx[i]=t[j][i];
for (i=1;i<=n;i++)
{
if (mx[i]<mx[i-1])
mx[i]=mx[i-1];
for (j=1;j<=i;j++)
if (mx[i] < mx[j-1]+t[j][i])
mx[i] = mx[j-1]+t[j][i];
}
printf ("%lld\n",mx[n]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |