Submission #15468

# Submission time Handle Problem Language Result Execution time Memory
15468 2015-07-12T08:07:46 Z cki86201 달리는 게임 (kriii3_E) C++
26 / 70
1000 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 Correct 0 ms 44052 KB Output is correct
3 Correct 0 ms 44052 KB Output is correct
4 Correct 4 ms 44052 KB Output is correct
5 Correct 0 ms 44052 KB Output is correct
6 Correct 0 ms 44052 KB Output is correct
7 Correct 0 ms 44052 KB Output is correct
8 Correct 0 ms 44052 KB Output is correct
9 Correct 0 ms 44052 KB Output is correct
10 Correct 4 ms 44052 KB Output is correct
11 Correct 0 ms 44052 KB Output is correct
12 Correct 0 ms 44052 KB Output is correct
13 Correct 2 ms 44052 KB Output is correct
14 Correct 5 ms 44052 KB Output is correct
15 Correct 0 ms 44052 KB Output is correct
16 Correct 5 ms 44052 KB Output is correct
17 Correct 5 ms 44052 KB Output is correct
18 Correct 0 ms 44052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 44052 KB Output is correct
2 Correct 31 ms 44052 KB Output is correct
3 Correct 24 ms 44052 KB Output is correct
4 Correct 47 ms 44052 KB Output is correct
5 Correct 659 ms 44052 KB Output is correct
6 Correct 62 ms 44052 KB Output is correct
7 Correct 527 ms 44052 KB Output is correct
8 Execution timed out 1000 ms 44052 KB Program timed out
9 Halted 0 ms 0 KB -