Submission #474201

# Submission time Handle Problem Language Result Execution time Memory
474201 2021-09-17T10:46:38 Z hoanghq2004 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
253 ms 15220 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 5e5 + 10;

int n;
long long dif[Nmax], ans;
priority_queue <long long> opt;

int main() {
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int a, b;
        cin >> a >> b;
        dif[i] = dif[i - 1] + a - b;
    }
    for (int i = 1; i < n; ++i) {
        if (dif[i] < 0) ans -= dif[i], dif[i] = 0;
        opt.push(dif[i]), opt.push(dif[i]);
        opt.pop();
        ans += dif[i];
    }
    while (opt.size()) ans -= min(dif[n], opt.top()), opt.pop();
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 17 ms 1356 KB Output is correct
5 Correct 36 ms 2140 KB Output is correct
6 Correct 116 ms 4460 KB Output is correct
7 Correct 171 ms 8440 KB Output is correct
8 Correct 198 ms 8436 KB Output is correct
9 Correct 170 ms 12584 KB Output is correct
10 Correct 144 ms 10404 KB Output is correct
11 Correct 151 ms 10420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 17 ms 1356 KB Output is correct
5 Correct 36 ms 2140 KB Output is correct
6 Correct 116 ms 4460 KB Output is correct
7 Correct 171 ms 8440 KB Output is correct
8 Correct 198 ms 8436 KB Output is correct
9 Correct 170 ms 12584 KB Output is correct
10 Correct 144 ms 10404 KB Output is correct
11 Correct 151 ms 10420 KB Output is correct
12 Correct 53 ms 4052 KB Output is correct
13 Correct 142 ms 10872 KB Output is correct
14 Correct 175 ms 15208 KB Output is correct
15 Correct 202 ms 13312 KB Output is correct
16 Correct 245 ms 12608 KB Output is correct
17 Correct 140 ms 10320 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 408 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 408 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 408 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 17 ms 1356 KB Output is correct
12 Correct 36 ms 2140 KB Output is correct
13 Correct 116 ms 4460 KB Output is correct
14 Correct 171 ms 8440 KB Output is correct
15 Correct 198 ms 8436 KB Output is correct
16 Correct 170 ms 12584 KB Output is correct
17 Correct 144 ms 10404 KB Output is correct
18 Correct 151 ms 10420 KB Output is correct
19 Correct 53 ms 4052 KB Output is correct
20 Correct 142 ms 10872 KB Output is correct
21 Correct 175 ms 15208 KB Output is correct
22 Correct 202 ms 13312 KB Output is correct
23 Correct 245 ms 12608 KB Output is correct
24 Correct 140 ms 10320 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 58 ms 4056 KB Output is correct
34 Correct 140 ms 10940 KB Output is correct
35 Correct 244 ms 15096 KB Output is correct
36 Correct 230 ms 12700 KB Output is correct
37 Correct 253 ms 13316 KB Output is correct
38 Correct 234 ms 15220 KB Output is correct
39 Correct 166 ms 11300 KB Output is correct
40 Correct 200 ms 10888 KB Output is correct
41 Correct 147 ms 10424 KB Output is correct
42 Correct 138 ms 10336 KB Output is correct
43 Correct 143 ms 10376 KB Output is correct
44 Correct 148 ms 10372 KB Output is correct
45 Correct 232 ms 15104 KB Output is correct
46 Correct 170 ms 10628 KB Output is correct
47 Correct 158 ms 10188 KB Output is correct