# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
623564 | 2022-08-05T23:01:44 Z | ipaljak | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 140 ms | 15224 KB |
#include <bits/stdc++.h> using namespace std; typedef long long llint; const int MAXN = 5e5 + 10; int n; llint sum; llint a[MAXN]; int main(void) { scanf("%d", &n); for (int i = 0; i < n; ++i) { int x, y; scanf("%d%d", &x, &y); if (i > 0) a[i] = a[i - 1]; a[i] += (llint)(x - y); } llint sol = 0; for (int i = 0; i < n; ++i) { if (a[i] < 0) { sol += -a[i]; a[i] = 0; } if (a[i] > a[n - 1]) { sol += a[i] - a[n - 1]; a[i] = a[n - 1]; } } priority_queue<llint> Q; for (int i = 0; i < n; ++i) { Q.push(a[i]); if (Q.top() > a[i]) { sol += Q.top() - a[i]; Q.pop(); Q.push(a[i]); } } printf("%lld\n", sol); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 9 ms | 1616 KB | Output is correct |
5 | Correct | 18 ms | 2856 KB | Output is correct |
6 | Correct | 47 ms | 7784 KB | Output is correct |
7 | Correct | 92 ms | 15176 KB | Output is correct |
8 | Correct | 84 ms | 13372 KB | Output is correct |
9 | Correct | 85 ms | 12572 KB | Output is correct |
10 | Correct | 77 ms | 10300 KB | Output is correct |
11 | Correct | 79 ms | 10300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 9 ms | 1616 KB | Output is correct |
5 | Correct | 18 ms | 2856 KB | Output is correct |
6 | Correct | 47 ms | 7784 KB | Output is correct |
7 | Correct | 92 ms | 15176 KB | Output is correct |
8 | Correct | 84 ms | 13372 KB | Output is correct |
9 | Correct | 85 ms | 12572 KB | Output is correct |
10 | Correct | 77 ms | 10300 KB | Output is correct |
11 | Correct | 79 ms | 10300 KB | Output is correct |
12 | Correct | 24 ms | 4048 KB | Output is correct |
13 | Correct | 56 ms | 10884 KB | Output is correct |
14 | Correct | 94 ms | 15224 KB | Output is correct |
15 | Correct | 94 ms | 13328 KB | Output is correct |
16 | Correct | 95 ms | 12644 KB | Output is correct |
17 | Correct | 82 ms | 10368 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 316 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 328 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 316 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 328 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 324 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 324 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 316 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 328 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 324 KB | Output is correct |
11 | Correct | 9 ms | 1616 KB | Output is correct |
12 | Correct | 18 ms | 2856 KB | Output is correct |
13 | Correct | 47 ms | 7784 KB | Output is correct |
14 | Correct | 92 ms | 15176 KB | Output is correct |
15 | Correct | 84 ms | 13372 KB | Output is correct |
16 | Correct | 85 ms | 12572 KB | Output is correct |
17 | Correct | 77 ms | 10300 KB | Output is correct |
18 | Correct | 79 ms | 10300 KB | Output is correct |
19 | Correct | 24 ms | 4048 KB | Output is correct |
20 | Correct | 56 ms | 10884 KB | Output is correct |
21 | Correct | 94 ms | 15224 KB | Output is correct |
22 | Correct | 94 ms | 13328 KB | Output is correct |
23 | Correct | 95 ms | 12644 KB | Output is correct |
24 | Correct | 82 ms | 10368 KB | Output is correct |
25 | Correct | 1 ms | 324 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 340 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 34 ms | 4036 KB | Output is correct |
34 | Correct | 86 ms | 10832 KB | Output is correct |
35 | Correct | 140 ms | 15156 KB | Output is correct |
36 | Correct | 138 ms | 12776 KB | Output is correct |
37 | Correct | 87 ms | 13240 KB | Output is correct |
38 | Correct | 130 ms | 15112 KB | Output is correct |
39 | Correct | 90 ms | 11260 KB | Output is correct |
40 | Correct | 92 ms | 10940 KB | Output is correct |
41 | Correct | 99 ms | 10388 KB | Output is correct |
42 | Correct | 96 ms | 10356 KB | Output is correct |
43 | Correct | 98 ms | 10300 KB | Output is correct |
44 | Correct | 103 ms | 10340 KB | Output is correct |
45 | Correct | 112 ms | 15164 KB | Output is correct |
46 | Correct | 80 ms | 10628 KB | Output is correct |
47 | Correct | 93 ms | 10168 KB | Output is correct |