Submission #950979

# Submission time Handle Problem Language Result Execution time Memory
950979 2024-03-21T03:26:46 Z daoquanglinh2007 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
148 ms 28804 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
const int NM = 5e5;
 
int n, a[NM+5], b[NM+5], c[NM+5], d[NM+5], cur = 0;
priority_queue <int> pq;
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
        c[i] = c[i-1]+a[i];
        d[i] = d[i-1]+b[i];
    }
    pq.push(0);
    for (int i = 1; i < n; i++){
        if (c[i]-d[i] >= pq.top()){
            pq.push(c[i]-d[i]);
            continue;
        }
        cur += pq.top()-(c[i]-d[i]);
        pq.pop();
        if (c[i]-d[i] > 0){
            pq.push(c[i]-d[i]);
            pq.push(c[i]-d[i]);
        }
        else{
            pq.push(0);
            pq.push(0);
        }
    }
    int lst = pq.top(), slope = 0;
    while (lst > c[n]-d[n]){
        cur += slope*(lst-max(c[n]-d[n], pq.top()));
        lst = pq.top();
        pq.pop();
        slope++;
    }
    cout << cur;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 11 ms 9696 KB Output is correct
5 Correct 24 ms 14360 KB Output is correct
6 Correct 79 ms 15308 KB Output is correct
7 Correct 85 ms 20428 KB Output is correct
8 Correct 117 ms 21704 KB Output is correct
9 Correct 89 ms 21764 KB Output is correct
10 Correct 77 ms 20720 KB Output is correct
11 Correct 83 ms 21484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 11 ms 9696 KB Output is correct
5 Correct 24 ms 14360 KB Output is correct
6 Correct 79 ms 15308 KB Output is correct
7 Correct 85 ms 20428 KB Output is correct
8 Correct 117 ms 21704 KB Output is correct
9 Correct 89 ms 21764 KB Output is correct
10 Correct 77 ms 20720 KB Output is correct
11 Correct 83 ms 21484 KB Output is correct
12 Correct 36 ms 14300 KB Output is correct
13 Correct 89 ms 23760 KB Output is correct
14 Correct 94 ms 27864 KB Output is correct
15 Correct 120 ms 25292 KB Output is correct
16 Correct 139 ms 26056 KB Output is correct
17 Correct 56 ms 22524 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4568 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4568 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4572 KB Output is correct
15 Correct 2 ms 4572 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4568 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 11 ms 9696 KB Output is correct
12 Correct 24 ms 14360 KB Output is correct
13 Correct 79 ms 15308 KB Output is correct
14 Correct 85 ms 20428 KB Output is correct
15 Correct 117 ms 21704 KB Output is correct
16 Correct 89 ms 21764 KB Output is correct
17 Correct 77 ms 20720 KB Output is correct
18 Correct 83 ms 21484 KB Output is correct
19 Correct 36 ms 14300 KB Output is correct
20 Correct 89 ms 23760 KB Output is correct
21 Correct 94 ms 27864 KB Output is correct
22 Correct 120 ms 25292 KB Output is correct
23 Correct 139 ms 26056 KB Output is correct
24 Correct 56 ms 22524 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 2 ms 4572 KB Output is correct
28 Correct 2 ms 4572 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 2 ms 4700 KB Output is correct
33 Correct 40 ms 16084 KB Output is correct
34 Correct 67 ms 22988 KB Output is correct
35 Correct 113 ms 28792 KB Output is correct
36 Correct 109 ms 25888 KB Output is correct
37 Correct 108 ms 25976 KB Output is correct
38 Correct 115 ms 28240 KB Output is correct
39 Correct 63 ms 24980 KB Output is correct
40 Correct 67 ms 23244 KB Output is correct
41 Correct 61 ms 22376 KB Output is correct
42 Correct 68 ms 24044 KB Output is correct
43 Correct 73 ms 22928 KB Output is correct
44 Correct 69 ms 22768 KB Output is correct
45 Correct 148 ms 28804 KB Output is correct
46 Correct 58 ms 23684 KB Output is correct
47 Correct 70 ms 22400 KB Output is correct