답안 #386301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386301 2021-04-06T10:14:07 Z johutha Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
239 ms 11252 KB
#include <iostream>
#include <vector>
#include <queue>

#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    priority_queue<int> q;
    int pf = 0;
    int v0 = 0;

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        int d = a - b;

        pf += d;
        q.push(max(0ll, pf));
        q.push(max(0ll, pf));
        q.pop();

        v0 += abs(pf);
    }

    int res = v0;
    while (q.size() > 0)
    {
        res -= min(q.top(), pf);
        q.pop();
    }

    cout << res << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 17 ms 1284 KB Output is correct
5 Correct 35 ms 2156 KB Output is correct
6 Correct 133 ms 5860 KB Output is correct
7 Correct 165 ms 11248 KB Output is correct
8 Correct 201 ms 9328 KB Output is correct
9 Correct 166 ms 8668 KB Output is correct
10 Correct 139 ms 6364 KB Output is correct
11 Correct 142 ms 6364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 17 ms 1284 KB Output is correct
5 Correct 35 ms 2156 KB Output is correct
6 Correct 133 ms 5860 KB Output is correct
7 Correct 165 ms 11248 KB Output is correct
8 Correct 201 ms 9328 KB Output is correct
9 Correct 166 ms 8668 KB Output is correct
10 Correct 139 ms 6364 KB Output is correct
11 Correct 142 ms 6364 KB Output is correct
12 Correct 53 ms 3468 KB Output is correct
13 Correct 130 ms 8420 KB Output is correct
14 Correct 176 ms 11140 KB Output is correct
15 Correct 196 ms 9308 KB Output is correct
16 Correct 217 ms 8836 KB Output is correct
17 Correct 143 ms 6364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 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 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 396 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 3 ms 492 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 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 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 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 17 ms 1284 KB Output is correct
12 Correct 35 ms 2156 KB Output is correct
13 Correct 133 ms 5860 KB Output is correct
14 Correct 165 ms 11248 KB Output is correct
15 Correct 201 ms 9328 KB Output is correct
16 Correct 166 ms 8668 KB Output is correct
17 Correct 139 ms 6364 KB Output is correct
18 Correct 142 ms 6364 KB Output is correct
19 Correct 53 ms 3468 KB Output is correct
20 Correct 130 ms 8420 KB Output is correct
21 Correct 176 ms 11140 KB Output is correct
22 Correct 196 ms 9308 KB Output is correct
23 Correct 217 ms 8836 KB Output is correct
24 Correct 143 ms 6364 KB Output is correct
25 Correct 2 ms 396 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 3 ms 492 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 492 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 53 ms 3176 KB Output is correct
34 Correct 141 ms 8460 KB Output is correct
35 Correct 239 ms 11100 KB Output is correct
36 Correct 229 ms 8796 KB Output is correct
37 Correct 207 ms 9320 KB Output is correct
38 Correct 223 ms 11100 KB Output is correct
39 Correct 163 ms 7388 KB Output is correct
40 Correct 171 ms 6928 KB Output is correct
41 Correct 137 ms 6364 KB Output is correct
42 Correct 137 ms 6408 KB Output is correct
43 Correct 142 ms 6408 KB Output is correct
44 Correct 151 ms 6424 KB Output is correct
45 Correct 223 ms 11252 KB Output is correct
46 Correct 206 ms 6636 KB Output is correct
47 Correct 164 ms 6688 KB Output is correct