답안 #203279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203279 2020-02-20T05:04:03 Z dolphingarlic Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
189 ms 15336 KB
#include <bits/stdc++.h>
using namespace std;

long long c[500001], ans = 0;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		long long a, b;
		cin >> a >> b;
		c[i] = c[i - 1] + a - b;
	}
	priority_queue<long long> pq;
	for (int i = 1; i <= n; i++) {
		if (c[i] > c[n]) {
			ans += c[i] - c[n];
			c[i] = c[n];
		} else if (c[i] < 0) {
			ans -= c[i];
			c[i] = 0;
		}
		pq.push(c[i]); pq.push(c[i]);
		ans += pq.top() - c[i];
		pq.pop();
	}
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 17 ms 1784 KB Output is correct
5 Correct 23 ms 2932 KB Output is correct
6 Correct 74 ms 7920 KB Output is correct
7 Correct 153 ms 15208 KB Output is correct
8 Correct 123 ms 13424 KB Output is correct
9 Correct 135 ms 12648 KB Output is correct
10 Correct 96 ms 10472 KB Output is correct
11 Correct 107 ms 10472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 17 ms 1784 KB Output is correct
5 Correct 23 ms 2932 KB Output is correct
6 Correct 74 ms 7920 KB Output is correct
7 Correct 153 ms 15208 KB Output is correct
8 Correct 123 ms 13424 KB Output is correct
9 Correct 135 ms 12648 KB Output is correct
10 Correct 96 ms 10472 KB Output is correct
11 Correct 107 ms 10472 KB Output is correct
12 Correct 42 ms 4208 KB Output is correct
13 Correct 100 ms 10984 KB Output is correct
14 Correct 160 ms 15196 KB Output is correct
15 Correct 124 ms 13544 KB Output is correct
16 Correct 123 ms 12776 KB Output is correct
17 Correct 98 ms 10472 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 248 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 248 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 17 ms 1784 KB Output is correct
12 Correct 23 ms 2932 KB Output is correct
13 Correct 74 ms 7920 KB Output is correct
14 Correct 153 ms 15208 KB Output is correct
15 Correct 123 ms 13424 KB Output is correct
16 Correct 135 ms 12648 KB Output is correct
17 Correct 96 ms 10472 KB Output is correct
18 Correct 107 ms 10472 KB Output is correct
19 Correct 42 ms 4208 KB Output is correct
20 Correct 100 ms 10984 KB Output is correct
21 Correct 160 ms 15196 KB Output is correct
22 Correct 124 ms 13544 KB Output is correct
23 Correct 123 ms 12776 KB Output is correct
24 Correct 98 ms 10472 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 6 ms 504 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 380 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 59 ms 4364 KB Output is correct
33 Correct 120 ms 10988 KB Output is correct
34 Correct 189 ms 15336 KB Output is correct
35 Correct 168 ms 12904 KB Output is correct
36 Correct 151 ms 13416 KB Output is correct
37 Correct 184 ms 15208 KB Output is correct
38 Correct 112 ms 11372 KB Output is correct
39 Correct 128 ms 10984 KB Output is correct
40 Correct 103 ms 10472 KB Output is correct
41 Correct 105 ms 10476 KB Output is correct
42 Correct 104 ms 10476 KB Output is correct
43 Correct 111 ms 10488 KB Output is correct
44 Correct 158 ms 15208 KB Output is correct
45 Correct 136 ms 10984 KB Output is correct
46 Correct 110 ms 10344 KB Output is correct
47 Correct 6 ms 504 KB Output is correct