답안 #474236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474236 2021-09-17T12:43:42 Z hoanghq2004 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
244 ms 11592 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1624 KB Output is correct
5 Correct 36 ms 2920 KB Output is correct
6 Correct 113 ms 7548 KB Output is correct
7 Correct 171 ms 11592 KB Output is correct
8 Correct 202 ms 11592 KB Output is correct
9 Correct 168 ms 9020 KB Output is correct
10 Correct 140 ms 8884 KB Output is correct
11 Correct 143 ms 9012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1624 KB Output is correct
5 Correct 36 ms 2920 KB Output is correct
6 Correct 113 ms 7548 KB Output is correct
7 Correct 171 ms 11592 KB Output is correct
8 Correct 202 ms 11592 KB Output is correct
9 Correct 168 ms 9020 KB Output is correct
10 Correct 140 ms 8884 KB Output is correct
11 Correct 143 ms 9012 KB Output is correct
12 Correct 54 ms 2984 KB Output is correct
13 Correct 136 ms 7356 KB Output is correct
14 Correct 181 ms 8892 KB Output is correct
15 Correct 205 ms 8888 KB Output is correct
16 Correct 214 ms 8888 KB Output is correct
17 Correct 144 ms 8908 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 332 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 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 17 ms 1624 KB Output is correct
12 Correct 36 ms 2920 KB Output is correct
13 Correct 113 ms 7548 KB Output is correct
14 Correct 171 ms 11592 KB Output is correct
15 Correct 202 ms 11592 KB Output is correct
16 Correct 168 ms 9020 KB Output is correct
17 Correct 140 ms 8884 KB Output is correct
18 Correct 143 ms 9012 KB Output is correct
19 Correct 54 ms 2984 KB Output is correct
20 Correct 136 ms 7356 KB Output is correct
21 Correct 181 ms 8892 KB Output is correct
22 Correct 205 ms 8888 KB Output is correct
23 Correct 214 ms 8888 KB Output is correct
24 Correct 144 ms 8908 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 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 55 ms 2900 KB Output is correct
34 Correct 136 ms 7392 KB Output is correct
35 Correct 244 ms 8864 KB Output is correct
36 Correct 233 ms 8924 KB Output is correct
37 Correct 197 ms 8972 KB Output is correct
38 Correct 227 ms 8972 KB Output is correct
39 Correct 159 ms 9020 KB Output is correct
40 Correct 176 ms 8576 KB Output is correct
41 Correct 145 ms 8940 KB Output is correct
42 Correct 138 ms 8900 KB Output is correct
43 Correct 140 ms 8988 KB Output is correct
44 Correct 143 ms 8992 KB Output is correct
45 Correct 224 ms 8904 KB Output is correct
46 Correct 174 ms 8892 KB Output is correct
47 Correct 153 ms 8056 KB Output is correct