Submission #236942

# Submission time Handle Problem Language Result Execution time Memory
236942 2020-06-04T04:52:53 Z PeppaPig Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
230 ms 18780 KB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 5e5 + 5;

int n;
long a[N], b[N], c[N], ans;

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%lld %lld", a + i, b + i);
        c[i] = c[i - 1] + a[i] - b[i];
    }
    priority_queue<long> Q;
    for(int i = 1; i <= n; i++) {
        if(c[i] > c[n]) ans += c[i] - c[n], c[i] = c[n];
        else if(c[i] < 0) ans -= c[i], c[i] = 0;
        Q.emplace(c[i]);
        if(c[i] < Q.top()) {
            ans += Q.top() - c[i];
            Q.pop(), Q.emplace(c[i]);
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bulves.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", a + i, b + i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 432 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 19 ms 2556 KB Output is correct
5 Correct 34 ms 4472 KB Output is correct
6 Correct 93 ms 10732 KB Output is correct
7 Correct 181 ms 18664 KB Output is correct
8 Correct 123 ms 18536 KB Output is correct
9 Correct 153 ms 18664 KB Output is correct
10 Correct 125 ms 18280 KB Output is correct
11 Correct 123 ms 18280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 432 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 19 ms 2556 KB Output is correct
5 Correct 34 ms 4472 KB Output is correct
6 Correct 93 ms 10732 KB Output is correct
7 Correct 181 ms 18664 KB Output is correct
8 Correct 123 ms 18536 KB Output is correct
9 Correct 153 ms 18664 KB Output is correct
10 Correct 125 ms 18280 KB Output is correct
11 Correct 123 ms 18280 KB Output is correct
12 Correct 48 ms 6128 KB Output is correct
13 Correct 101 ms 13928 KB Output is correct
14 Correct 203 ms 18536 KB Output is correct
15 Correct 141 ms 18536 KB Output is correct
16 Correct 140 ms 18596 KB Output is correct
17 Correct 147 ms 18196 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 432 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 432 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 6 ms 520 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 432 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 19 ms 2556 KB Output is correct
12 Correct 34 ms 4472 KB Output is correct
13 Correct 93 ms 10732 KB Output is correct
14 Correct 181 ms 18664 KB Output is correct
15 Correct 123 ms 18536 KB Output is correct
16 Correct 153 ms 18664 KB Output is correct
17 Correct 125 ms 18280 KB Output is correct
18 Correct 123 ms 18280 KB Output is correct
19 Correct 48 ms 6128 KB Output is correct
20 Correct 101 ms 13928 KB Output is correct
21 Correct 203 ms 18536 KB Output is correct
22 Correct 141 ms 18536 KB Output is correct
23 Correct 140 ms 18596 KB Output is correct
24 Correct 147 ms 18196 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 6 ms 520 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 58 ms 6128 KB Output is correct
33 Correct 146 ms 14032 KB Output is correct
34 Correct 229 ms 18640 KB Output is correct
35 Correct 218 ms 18536 KB Output is correct
36 Correct 135 ms 18584 KB Output is correct
37 Correct 230 ms 18668 KB Output is correct
38 Correct 142 ms 18536 KB Output is correct
39 Correct 135 ms 17512 KB Output is correct
40 Correct 143 ms 18340 KB Output is correct
41 Correct 146 ms 18280 KB Output is correct
42 Correct 140 ms 18280 KB Output is correct
43 Correct 146 ms 18280 KB Output is correct
44 Correct 178 ms 18780 KB Output is correct
45 Correct 123 ms 18664 KB Output is correct
46 Correct 141 ms 16072 KB Output is correct
47 Correct 6 ms 512 KB Output is correct