답안 #567934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567934 2022-05-24T11:18:58 Z four_specks Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
156 ms 19128 KB
#include <bits/stdc++.h>

using namespace std;

inline namespace
{
} // namespace

void solve()
{
    int n;
    cin >> n;

    vector<long> a(n), b(n);
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i];

    long c = 0;
    for (int i = 0; i < n; i++)
        c += a[i] - b[i];

    long cost = 0;

    priority_queue<long> pq;
    long d = 0;
    for (int i = 0; i < n; i++)
    {
        d += a[i] - b[i];

        long e = d;
        if (e < 0)
        {
            cost -= e;
            e = 0;
        }
        else if (e > c)
        {
            cost += e - c;
            e = c;
        }

        pq.push(e), pq.push(e);
        cost += pq.top() - e;
        pq.pop();
    }

    cout << cost << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 10 ms 2004 KB Output is correct
5 Correct 17 ms 3668 KB Output is correct
6 Correct 54 ms 9728 KB Output is correct
7 Correct 107 ms 19128 KB Output is correct
8 Correct 104 ms 17208 KB Output is correct
9 Correct 113 ms 16568 KB Output is correct
10 Correct 78 ms 14316 KB Output is correct
11 Correct 72 ms 14272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 10 ms 2004 KB Output is correct
5 Correct 17 ms 3668 KB Output is correct
6 Correct 54 ms 9728 KB Output is correct
7 Correct 107 ms 19128 KB Output is correct
8 Correct 104 ms 17208 KB Output is correct
9 Correct 113 ms 16568 KB Output is correct
10 Correct 78 ms 14316 KB Output is correct
11 Correct 72 ms 14272 KB Output is correct
12 Correct 28 ms 5112 KB Output is correct
13 Correct 72 ms 13176 KB Output is correct
14 Correct 121 ms 19048 KB Output is correct
15 Correct 127 ms 17208 KB Output is correct
16 Correct 89 ms 16560 KB Output is correct
17 Correct 83 ms 14264 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 10 ms 2004 KB Output is correct
12 Correct 17 ms 3668 KB Output is correct
13 Correct 54 ms 9728 KB Output is correct
14 Correct 107 ms 19128 KB Output is correct
15 Correct 104 ms 17208 KB Output is correct
16 Correct 113 ms 16568 KB Output is correct
17 Correct 78 ms 14316 KB Output is correct
18 Correct 72 ms 14272 KB Output is correct
19 Correct 28 ms 5112 KB Output is correct
20 Correct 72 ms 13176 KB Output is correct
21 Correct 121 ms 19048 KB Output is correct
22 Correct 127 ms 17208 KB Output is correct
23 Correct 89 ms 16560 KB Output is correct
24 Correct 83 ms 14264 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 37 ms 5092 KB Output is correct
34 Correct 92 ms 13180 KB Output is correct
35 Correct 156 ms 19128 KB Output is correct
36 Correct 147 ms 16700 KB Output is correct
37 Correct 114 ms 17260 KB Output is correct
38 Correct 153 ms 19108 KB Output is correct
39 Correct 90 ms 15284 KB Output is correct
40 Correct 102 ms 14456 KB Output is correct
41 Correct 87 ms 14264 KB Output is correct
42 Correct 95 ms 14228 KB Output is correct
43 Correct 118 ms 14268 KB Output is correct
44 Correct 86 ms 14276 KB Output is correct
45 Correct 122 ms 19092 KB Output is correct
46 Correct 114 ms 14632 KB Output is correct
47 Correct 95 ms 13316 KB Output is correct