Submission #15465

# Submission time Handle Problem Language Result Execution time Memory
15465 2015-07-12T08:04:22 Z cki86201 달리는 게임 (kriii3_E) C++
0 / 70
6 ms 44052 KB
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<set>
#include<algorithm>

typedef long long ll;
typedef std::pair<ll, ll> pl;
#define X first
#define Y second

const int MX = 1000010;

int n, a[MX];
ll s[MX], ss[MX];
ll d[MX];
struct lines{
	pl p[MX];
	int f;
	void init(){ f = 0; }
	void push(pl x){
		while (f>1 && (double)(p[f - 1].X - p[f - 2].X) * (x.Y - p[f - 1].Y) >= (double)(x.X - p[f - 1].X) * (p[f - 1].Y - p[f - 2].Y))--f;
		p[f++] = x;
	}
	ll get(ll x){
		ll ret = 0;
		for (int i = 0; i < f; i++)ret = std::max(ret, x * p[i].X + p[i].Y);
		return ret;
	}
}Lin;

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", a + i);
	for (int i = 1; i <= n; i++)s[i] = s[i - 1] + a[i];
	for (int i = 1; i <= n; i++)ss[i] = ss[i - 1] + s[i];
	Lin.init();
	Lin.push(pl(0, 0));
	for (int i = 1; i <= n; i++){
		d[i] = Lin.get(s[i]) + s[i] * i - ss[i-1];
		if (d[i] < d[i - 1])d[i] = d[i - 1];
		Lin.push(pl(-i, d[i] + ss[i - 1]));
		//printf("%d : %d\n", i, d[i]);
	}
	printf("%lld", d[n]);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44052 KB Output is correct
2 Incorrect 0 ms 44052 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -