# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384151 | 2021-03-31T14:44:06 Z | LucaDantas | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 194 ms | 15340 KB |
#include <cstdio> #include <queue> std::priority_queue<long long> q; int main() { int n; scanf("%d", &n); long long d[n+1]{}, ans = 0; for(int i = 1; i <= n; i++) { int a, b; scanf("%d %d", &a, &b); d[i] = d[i-1] + a - b; } for(int i = 1; i <= n; i++) { if(d[i] < 0) ans -= d[i], d[i] = 0; else if(d[i] > d[n]) ans += d[i] - d[n], d[i] = d[n]; q.push(d[i]); if(d[i] < q.top()) ans += q.top() - d[i], q.pop(), q.push(d[i]); } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 13 ms | 1640 KB | Output is correct |
5 | Correct | 24 ms | 2916 KB | Output is correct |
6 | Correct | 64 ms | 7776 KB | Output is correct |
7 | Correct | 127 ms | 15324 KB | Output is correct |
8 | Correct | 110 ms | 13404 KB | Output is correct |
9 | Correct | 113 ms | 12656 KB | Output is correct |
10 | Correct | 112 ms | 10460 KB | Output is correct |
11 | Correct | 109 ms | 10460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 13 ms | 1640 KB | Output is correct |
5 | Correct | 24 ms | 2916 KB | Output is correct |
6 | Correct | 64 ms | 7776 KB | Output is correct |
7 | Correct | 127 ms | 15324 KB | Output is correct |
8 | Correct | 110 ms | 13404 KB | Output is correct |
9 | Correct | 113 ms | 12656 KB | Output is correct |
10 | Correct | 112 ms | 10460 KB | Output is correct |
11 | Correct | 109 ms | 10460 KB | Output is correct |
12 | Correct | 34 ms | 4068 KB | Output is correct |
13 | Correct | 104 ms | 11004 KB | Output is correct |
14 | Correct | 130 ms | 15256 KB | Output is correct |
15 | Correct | 109 ms | 13404 KB | Output is correct |
16 | Correct | 127 ms | 12636 KB | Output is correct |
17 | Correct | 118 ms | 10460 KB | Output is correct |
18 | Correct | 2 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 2 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 364 KB | Output is correct |
8 | Correct | 2 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 2 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 364 KB | Output is correct |
8 | Correct | 2 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 2 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
13 | Correct | 2 ms | 364 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 364 KB | Output is correct |
16 | Correct | 2 ms | 364 KB | Output is correct |
17 | Correct | 2 ms | 364 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 2 ms | 364 KB | Output is correct |
7 | Correct | 2 ms | 364 KB | Output is correct |
8 | Correct | 2 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 2 ms | 364 KB | Output is correct |
11 | Correct | 13 ms | 1640 KB | Output is correct |
12 | Correct | 24 ms | 2916 KB | Output is correct |
13 | Correct | 64 ms | 7776 KB | Output is correct |
14 | Correct | 127 ms | 15324 KB | Output is correct |
15 | Correct | 110 ms | 13404 KB | Output is correct |
16 | Correct | 113 ms | 12656 KB | Output is correct |
17 | Correct | 112 ms | 10460 KB | Output is correct |
18 | Correct | 109 ms | 10460 KB | Output is correct |
19 | Correct | 34 ms | 4068 KB | Output is correct |
20 | Correct | 104 ms | 11004 KB | Output is correct |
21 | Correct | 130 ms | 15256 KB | Output is correct |
22 | Correct | 109 ms | 13404 KB | Output is correct |
23 | Correct | 127 ms | 12636 KB | Output is correct |
24 | Correct | 118 ms | 10460 KB | Output is correct |
25 | Correct | 2 ms | 364 KB | Output is correct |
26 | Correct | 2 ms | 364 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 364 KB | Output is correct |
29 | Correct | 2 ms | 364 KB | Output is correct |
30 | Correct | 2 ms | 364 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 364 KB | Output is correct |
33 | Correct | 46 ms | 4068 KB | Output is correct |
34 | Correct | 113 ms | 10972 KB | Output is correct |
35 | Correct | 194 ms | 15340 KB | Output is correct |
36 | Correct | 186 ms | 12892 KB | Output is correct |
37 | Correct | 117 ms | 13404 KB | Output is correct |
38 | Correct | 179 ms | 15324 KB | Output is correct |
39 | Correct | 127 ms | 11356 KB | Output is correct |
40 | Correct | 128 ms | 10972 KB | Output is correct |
41 | Correct | 166 ms | 10460 KB | Output is correct |
42 | Correct | 133 ms | 10460 KB | Output is correct |
43 | Correct | 136 ms | 10460 KB | Output is correct |
44 | Correct | 140 ms | 10444 KB | Output is correct |
45 | Correct | 152 ms | 15196 KB | Output is correct |
46 | Correct | 115 ms | 10844 KB | Output is correct |
47 | Correct | 127 ms | 10204 KB | Output is correct |