Submission #717882

# Submission time Handle Problem Language Result Execution time Memory
717882 2023-04-02T18:43:16 Z KLKLK Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
210 ms 15212 KB
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>

#define LL long long

using namespace std;

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

    int n;
    cin >> n;

    vector<LL> diff(n + 1);
    priority_queue<LL> Q;

    int a, b;
    LL res = 0;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a >> b;
        diff[i] = a - b;
        diff[i] += diff[i - 1];
    }

    for (int i = 1; i < n; ++i)
    {
        if (diff[i] < 0)
        {
            res -= diff[i];
            diff[i] = 0;
        }
        else res += diff[i];

        Q.push(diff[i]);
        Q.push(diff[i]);
        Q.pop();
    }

    while (!Q.empty())
    {
        LL x = Q.top();
        Q.pop();
        res -= min(x, diff[n]);
    }

    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 14 ms 1624 KB Output is correct
5 Correct 29 ms 2880 KB Output is correct
6 Correct 95 ms 7824 KB Output is correct
7 Correct 140 ms 15212 KB Output is correct
8 Correct 165 ms 13292 KB Output is correct
9 Correct 134 ms 12652 KB Output is correct
10 Correct 103 ms 10360 KB Output is correct
11 Correct 115 ms 10360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 14 ms 1624 KB Output is correct
5 Correct 29 ms 2880 KB Output is correct
6 Correct 95 ms 7824 KB Output is correct
7 Correct 140 ms 15212 KB Output is correct
8 Correct 165 ms 13292 KB Output is correct
9 Correct 134 ms 12652 KB Output is correct
10 Correct 103 ms 10360 KB Output is correct
11 Correct 115 ms 10360 KB Output is correct
12 Correct 45 ms 4092 KB Output is correct
13 Correct 111 ms 10916 KB Output is correct
14 Correct 140 ms 15212 KB Output is correct
15 Correct 170 ms 13292 KB Output is correct
16 Correct 173 ms 12660 KB Output is correct
17 Correct 106 ms 10344 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
11 Correct 14 ms 1624 KB Output is correct
12 Correct 29 ms 2880 KB Output is correct
13 Correct 95 ms 7824 KB Output is correct
14 Correct 140 ms 15212 KB Output is correct
15 Correct 165 ms 13292 KB Output is correct
16 Correct 134 ms 12652 KB Output is correct
17 Correct 103 ms 10360 KB Output is correct
18 Correct 115 ms 10360 KB Output is correct
19 Correct 45 ms 4092 KB Output is correct
20 Correct 111 ms 10916 KB Output is correct
21 Correct 140 ms 15212 KB Output is correct
22 Correct 170 ms 13292 KB Output is correct
23 Correct 173 ms 12660 KB Output is correct
24 Correct 106 ms 10344 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 328 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 45 ms 4104 KB Output is correct
34 Correct 126 ms 10824 KB Output is correct
35 Correct 205 ms 15212 KB Output is correct
36 Correct 195 ms 12716 KB Output is correct
37 Correct 189 ms 13292 KB Output is correct
38 Correct 210 ms 15212 KB Output is correct
39 Correct 125 ms 11328 KB Output is correct
40 Correct 163 ms 10876 KB Output is correct
41 Correct 109 ms 10400 KB Output is correct
42 Correct 100 ms 10408 KB Output is correct
43 Correct 104 ms 10348 KB Output is correct
44 Correct 103 ms 10352 KB Output is correct
45 Correct 182 ms 15092 KB Output is correct
46 Correct 134 ms 10692 KB Output is correct
47 Correct 133 ms 10420 KB Output is correct