# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331360 | 2020-11-28T06:00:29 Z | Nson | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 510 ms | 30572 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; scanf("%d", &n); multiset<ll> s; ll m = 0, b = 0; // y = m * x + b auto apply_prefix_min = [&]() { while(!s.empty() and m > 0) { m--; b += *prev(s.end()); s.erase(prev(s.end())); } }; ll d = 0; for(int i = 0; i < n; i++) { int aa, bb; scanf("%d %d", &aa, &bb); aa -= bb; d += aa; apply_prefix_min(); if(d >= 0) { s.insert(d); s.insert(d); b -= d; m += 1; } else { s.insert(0); m += 1; b -= d; } } while(!s.empty() and *prev(s.end()) > d) { m--; b += *prev(s.end()); s.erase(prev(s.end())); } printf("%lld\n", d * m + b); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 26 ms | 2028 KB | Output is correct |
5 | Correct | 57 ms | 4332 KB | Output is correct |
6 | Correct | 167 ms | 12780 KB | Output is correct |
7 | Correct | 171 ms | 3564 KB | Output is correct |
8 | Correct | 303 ms | 24448 KB | Output is correct |
9 | Correct | 222 ms | 8556 KB | Output is correct |
10 | Correct | 328 ms | 24812 KB | Output is correct |
11 | Correct | 288 ms | 24684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 26 ms | 2028 KB | Output is correct |
5 | Correct | 57 ms | 4332 KB | Output is correct |
6 | Correct | 167 ms | 12780 KB | Output is correct |
7 | Correct | 171 ms | 3564 KB | Output is correct |
8 | Correct | 303 ms | 24448 KB | Output is correct |
9 | Correct | 222 ms | 8556 KB | Output is correct |
10 | Correct | 328 ms | 24812 KB | Output is correct |
11 | Correct | 288 ms | 24684 KB | Output is correct |
12 | Correct | 88 ms | 6124 KB | Output is correct |
13 | Correct | 288 ms | 16236 KB | Output is correct |
14 | Correct | 194 ms | 10604 KB | Output is correct |
15 | Correct | 294 ms | 28780 KB | Output is correct |
16 | Correct | 510 ms | 23712 KB | Output is correct |
17 | Correct | 247 ms | 25708 KB | Output is correct |
18 | Correct | 2 ms | 492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 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 | 364 KB | Output is correct |
6 | Correct | 2 ms | 492 KB | Output is correct |
7 | Correct | 3 ms | 492 KB | Output is correct |
8 | Correct | 2 ms | 492 KB | Output is correct |
9 | Correct | 3 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 364 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 | 364 KB | Output is correct |
7 | Correct | 2 ms | 492 KB | Output is correct |
8 | Correct | 3 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 3 ms | 492 KB | Output is correct |
11 | Correct | 2 ms | 492 KB | Output is correct |
12 | Correct | 3 ms | 492 KB | Output is correct |
13 | Correct | 3 ms | 492 KB | Output is correct |
14 | Correct | 2 ms | 492 KB | Output is correct |
15 | Correct | 2 ms | 492 KB | Output is correct |
16 | Correct | 2 ms | 492 KB | Output is correct |
17 | Correct | 3 ms | 364 KB | Output is correct |
18 | Correct | 2 ms | 492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 492 KB | Output is correct |
3 | Correct | 2 ms | 364 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 | 364 KB | Output is correct |
7 | Correct | 2 ms | 492 KB | Output is correct |
8 | Correct | 3 ms | 492 KB | Output is correct |
9 | Correct | 2 ms | 492 KB | Output is correct |
10 | Correct | 3 ms | 492 KB | Output is correct |
11 | Correct | 26 ms | 2028 KB | Output is correct |
12 | Correct | 57 ms | 4332 KB | Output is correct |
13 | Correct | 167 ms | 12780 KB | Output is correct |
14 | Correct | 171 ms | 3564 KB | Output is correct |
15 | Correct | 303 ms | 24448 KB | Output is correct |
16 | Correct | 222 ms | 8556 KB | Output is correct |
17 | Correct | 328 ms | 24812 KB | Output is correct |
18 | Correct | 288 ms | 24684 KB | Output is correct |
19 | Correct | 88 ms | 6124 KB | Output is correct |
20 | Correct | 288 ms | 16236 KB | Output is correct |
21 | Correct | 194 ms | 10604 KB | Output is correct |
22 | Correct | 294 ms | 28780 KB | Output is correct |
23 | Correct | 510 ms | 23712 KB | Output is correct |
24 | Correct | 247 ms | 25708 KB | Output is correct |
25 | Correct | 2 ms | 492 KB | Output is correct |
26 | Correct | 3 ms | 492 KB | Output is correct |
27 | Correct | 3 ms | 492 KB | Output is correct |
28 | Correct | 2 ms | 492 KB | Output is correct |
29 | Correct | 2 ms | 492 KB | Output is correct |
30 | Correct | 2 ms | 492 KB | Output is correct |
31 | Correct | 3 ms | 364 KB | Output is correct |
32 | Correct | 77 ms | 7916 KB | Output is correct |
33 | Correct | 191 ms | 18540 KB | Output is correct |
34 | Correct | 371 ms | 30380 KB | Output is correct |
35 | Correct | 491 ms | 28140 KB | Output is correct |
36 | Correct | 342 ms | 28780 KB | Output is correct |
37 | Correct | 346 ms | 30572 KB | Output is correct |
38 | Correct | 306 ms | 26732 KB | Output is correct |
39 | Correct | 262 ms | 24556 KB | Output is correct |
40 | Correct | 356 ms | 25708 KB | Output is correct |
41 | Correct | 292 ms | 25836 KB | Output is correct |
42 | Correct | 280 ms | 25736 KB | Output is correct |
43 | Correct | 271 ms | 25964 KB | Output is correct |
44 | Correct | 385 ms | 25580 KB | Output is correct |
45 | Correct | 294 ms | 26092 KB | Output is correct |
46 | Correct | 275 ms | 21228 KB | Output is correct |
47 | Correct | 2 ms | 492 KB | Output is correct |