답안 #236912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236912 2020-06-03T19:00:31 Z Benq Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
595 ms 15368 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int N;
ll fst = 0; // value of DP function at 0
priority_queue<ll> points; // points where DP function changes slope

int main() {
	cin >> N;
	vector<ll> dif(N+1);
	for (int i = 1; i <= N; ++i) {
		int a,b; cin >> a >> b;
		dif[i] = a-b+dif[i-1];
	}
	assert(dif[N] >= 0);
	for (int i = 1; i < N; ++i) {
		if (dif[i] < 0) fst -= dif[i], dif[i] = 0;
		fst += dif[i];
		points.push(dif[i]); points.push(dif[i]);
		points.pop();
	}
	while (points.size()) {
		ll a = points.top(); points.pop();
		fst -= min(a,dif[N]);
	}
	cout << fst << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 40 ms 1652 KB Output is correct
5 Correct 79 ms 2928 KB Output is correct
6 Correct 288 ms 7788 KB Output is correct
7 Correct 535 ms 15336 KB Output is correct
8 Correct 477 ms 13416 KB Output is correct
9 Correct 404 ms 12648 KB Output is correct
10 Correct 279 ms 10472 KB Output is correct
11 Correct 282 ms 10472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 40 ms 1652 KB Output is correct
5 Correct 79 ms 2928 KB Output is correct
6 Correct 288 ms 7788 KB Output is correct
7 Correct 535 ms 15336 KB Output is correct
8 Correct 477 ms 13416 KB Output is correct
9 Correct 404 ms 12648 KB Output is correct
10 Correct 279 ms 10472 KB Output is correct
11 Correct 282 ms 10472 KB Output is correct
12 Correct 144 ms 4080 KB Output is correct
13 Correct 374 ms 10960 KB Output is correct
14 Correct 523 ms 15264 KB Output is correct
15 Correct 475 ms 13416 KB Output is correct
16 Correct 474 ms 12648 KB Output is correct
17 Correct 275 ms 10532 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 8 ms 384 KB Output is correct
12 Correct 8 ms 384 KB Output is correct
13 Correct 8 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 40 ms 1652 KB Output is correct
12 Correct 79 ms 2928 KB Output is correct
13 Correct 288 ms 7788 KB Output is correct
14 Correct 535 ms 15336 KB Output is correct
15 Correct 477 ms 13416 KB Output is correct
16 Correct 404 ms 12648 KB Output is correct
17 Correct 279 ms 10472 KB Output is correct
18 Correct 282 ms 10472 KB Output is correct
19 Correct 144 ms 4080 KB Output is correct
20 Correct 374 ms 10960 KB Output is correct
21 Correct 523 ms 15264 KB Output is correct
22 Correct 475 ms 13416 KB Output is correct
23 Correct 474 ms 12648 KB Output is correct
24 Correct 275 ms 10532 KB Output is correct
25 Correct 8 ms 384 KB Output is correct
26 Correct 8 ms 384 KB Output is correct
27 Correct 8 ms 384 KB Output is correct
28 Correct 7 ms 384 KB Output is correct
29 Correct 7 ms 384 KB Output is correct
30 Correct 7 ms 384 KB Output is correct
31 Correct 8 ms 384 KB Output is correct
32 Correct 146 ms 4208 KB Output is correct
33 Correct 362 ms 10984 KB Output is correct
34 Correct 591 ms 15368 KB Output is correct
35 Correct 471 ms 12932 KB Output is correct
36 Correct 464 ms 13416 KB Output is correct
37 Correct 595 ms 15336 KB Output is correct
38 Correct 341 ms 11368 KB Output is correct
39 Correct 351 ms 10984 KB Output is correct
40 Correct 283 ms 10472 KB Output is correct
41 Correct 282 ms 10600 KB Output is correct
42 Correct 273 ms 10472 KB Output is correct
43 Correct 282 ms 10472 KB Output is correct
44 Correct 585 ms 15336 KB Output is correct
45 Correct 339 ms 10728 KB Output is correct
46 Correct 316 ms 10344 KB Output is correct
47 Correct 6 ms 384 KB Output is correct