Submission #15230

#TimeUsernameProblemLanguageResultExecution timeMemory
15230myungwoo달리는 게임 (kriii3_E)C++14
26 / 70
1000 ms29064 KiB
#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] = D[i-1];
		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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...