Submission #15220

#TimeUsernameProblemLanguageResultExecution timeMemory
15220gs14004달리는 게임 (kriii3_E)C++14
26 / 70
1000 ms32332 KiB
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long lint;

int n;
lint dp[1000005];
lint a[1000005];
lint s1[1000005];
lint s2[1000005];

int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%lld",&a[i]);
		s1[i] = s1[i-1] + a[i];
		s2[i] = s2[i-1] + s1[i];
	}
	for(int i=1; i<=n; i++){
		dp[i] = dp[i-1];
		for(int j=0; j<i; j++){
			dp[i] = max(dp[i], dp[j] + s1[i] * (i - j) - s2[i-1] + (j ? s2[j-1] : 0));
		}
	}
	printf("%lld",dp[n]);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...