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;
#define MAXN 1000006
typedef long long lld;
int N;
int A[MAXN];
lld D[MAXN], Nu[MAXN], S[MAXN];
int main()
{
scanf("%d", &N);
for (int i=1;i<=N;i++) scanf("%d", A+i);
for (int i=1;i<=N;i++) Nu[i] = Nu[i-1] + (lld)i * A[i], S[i] = S[i-1] + A[i];
lld ans = 0;
for (int i=1;i<=N;i++){
D[i] = 0;
for (int j=0;j<i;j++){
D[i] = max(D[i], D[j] - Nu[j] + S[j] * j - S[i] * j + Nu[i]);
}
ans = max(ans, D[i]);
}
printf("%lld\n", ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |