Submission #334236

# Submission time Handle Problem Language Result Execution time Memory
334236 2020-12-08T17:50:35 Z ttnhuy313 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
185 ms 23312 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

const int N = 5e5 + 5;
int n, a[N], b[N], c[N];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i];
		c[i] = c[i - 1] + a[i] - b[i];
	}
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		if (c[i] < 0) {
			res += -c[i];
			c[i] = 0;
		}
		if (c[i] > c[n]) {
			res += c[i] - c[n];
			c[i] = c[n];
		}
	}
	priority_queue <int> pq;
	while (!pq.empty()) pq.pop();
	for (int i = 1; i <= n; ++i) {
		pq.push(c[i]);
		if (c[i] < pq.top()) {
			res += pq.top() - c[i];
			pq.pop();
			pq.push(c[i]);
		}
	}
	cout << res << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 9 ms 2544 KB Output is correct
5 Correct 21 ms 4588 KB Output is correct
6 Correct 54 ms 11752 KB Output is correct
7 Correct 117 ms 23312 KB Output is correct
8 Correct 92 ms 21220 KB Output is correct
9 Correct 90 ms 20648 KB Output is correct
10 Correct 73 ms 18276 KB Output is correct
11 Correct 73 ms 18276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 9 ms 2544 KB Output is correct
5 Correct 21 ms 4588 KB Output is correct
6 Correct 54 ms 11752 KB Output is correct
7 Correct 117 ms 23312 KB Output is correct
8 Correct 92 ms 21220 KB Output is correct
9 Correct 90 ms 20648 KB Output is correct
10 Correct 73 ms 18276 KB Output is correct
11 Correct 73 ms 18276 KB Output is correct
12 Correct 28 ms 6124 KB Output is correct
13 Correct 71 ms 15716 KB Output is correct
14 Correct 117 ms 23140 KB Output is correct
15 Correct 92 ms 21220 KB Output is correct
16 Correct 101 ms 20580 KB Output is correct
17 Correct 90 ms 18276 KB Output is correct
18 Correct 1 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 1 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 9 ms 2544 KB Output is correct
12 Correct 21 ms 4588 KB Output is correct
13 Correct 54 ms 11752 KB Output is correct
14 Correct 117 ms 23312 KB Output is correct
15 Correct 92 ms 21220 KB Output is correct
16 Correct 90 ms 20648 KB Output is correct
17 Correct 73 ms 18276 KB Output is correct
18 Correct 73 ms 18276 KB Output is correct
19 Correct 28 ms 6124 KB Output is correct
20 Correct 71 ms 15716 KB Output is correct
21 Correct 117 ms 23140 KB Output is correct
22 Correct 92 ms 21220 KB Output is correct
23 Correct 101 ms 20580 KB Output is correct
24 Correct 90 ms 18276 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 43 ms 6380 KB Output is correct
33 Correct 119 ms 15716 KB Output is correct
34 Correct 185 ms 23268 KB Output is correct
35 Correct 160 ms 20824 KB Output is correct
36 Correct 109 ms 21348 KB Output is correct
37 Correct 157 ms 23160 KB Output is correct
38 Correct 101 ms 19388 KB Output is correct
39 Correct 110 ms 18148 KB Output is correct
40 Correct 97 ms 18276 KB Output is correct
41 Correct 97 ms 18404 KB Output is correct
42 Correct 102 ms 18276 KB Output is correct
43 Correct 102 ms 18276 KB Output is correct
44 Correct 123 ms 23140 KB Output is correct
45 Correct 89 ms 18660 KB Output is correct
46 Correct 105 ms 16484 KB Output is correct
47 Correct 1 ms 524 KB Output is correct