Submission #795401

# Submission time Handle Problem Language Result Execution time Memory
795401 2023-07-27T09:04:12 Z ttamx Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
148 ms 23096 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=5e5+5;

int n;
ll a[N],b[N],d[N];
ll ans;
priority_queue<ll> pq;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i=1;i<=n;i++)cin >> a[i] >> b[i];
    for(int i=1;i<=n;i++)d[i]=d[i-1]+a[i]-b[i];
    for(int i=1;i<n;i++){
        if(d[i]<0)ans-=d[i],d[i]=0;
        pq.emplace(d[i]);
        pq.emplace(d[i]);
        ans+=pq.top()-d[i];
        pq.pop();
    }
    ll mul=1;
    while(!pq.empty()&&pq.top()>d[n]){
        ans+=max(0ll,pq.top()-d[n]);
        pq.pop();
    }
    cout << ans;
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:26:8: warning: unused variable 'mul' [-Wunused-variable]
   26 |     ll mul=1;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 11 ms 2392 KB Output is correct
5 Correct 23 ms 4452 KB Output is correct
6 Correct 79 ms 11752 KB Output is correct
7 Correct 90 ms 23052 KB Output is correct
8 Correct 148 ms 21248 KB Output is correct
9 Correct 94 ms 20468 KB Output is correct
10 Correct 81 ms 18204 KB Output is correct
11 Correct 90 ms 18216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 11 ms 2392 KB Output is correct
5 Correct 23 ms 4452 KB Output is correct
6 Correct 79 ms 11752 KB Output is correct
7 Correct 90 ms 23052 KB Output is correct
8 Correct 148 ms 21248 KB Output is correct
9 Correct 94 ms 20468 KB Output is correct
10 Correct 81 ms 18204 KB Output is correct
11 Correct 90 ms 18216 KB Output is correct
12 Correct 36 ms 6100 KB Output is correct
13 Correct 90 ms 15608 KB Output is correct
14 Correct 93 ms 22992 KB Output is correct
15 Correct 139 ms 21128 KB Output is correct
16 Correct 141 ms 20476 KB Output is correct
17 Correct 72 ms 18168 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 0 ms 340 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 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 340 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 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 340 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 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 11 ms 2392 KB Output is correct
12 Correct 23 ms 4452 KB Output is correct
13 Correct 79 ms 11752 KB Output is correct
14 Correct 90 ms 23052 KB Output is correct
15 Correct 148 ms 21248 KB Output is correct
16 Correct 94 ms 20468 KB Output is correct
17 Correct 81 ms 18204 KB Output is correct
18 Correct 90 ms 18216 KB Output is correct
19 Correct 36 ms 6100 KB Output is correct
20 Correct 90 ms 15608 KB Output is correct
21 Correct 93 ms 22992 KB Output is correct
22 Correct 139 ms 21128 KB Output is correct
23 Correct 141 ms 20476 KB Output is correct
24 Correct 72 ms 18168 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 504 KB Output is correct
33 Correct 29 ms 6092 KB Output is correct
34 Correct 69 ms 15636 KB Output is correct
35 Correct 126 ms 23004 KB Output is correct
36 Correct 104 ms 20648 KB Output is correct
37 Correct 126 ms 21152 KB Output is correct
38 Correct 111 ms 22984 KB Output is correct
39 Correct 73 ms 19144 KB Output is correct
40 Correct 82 ms 17984 KB Output is correct
41 Correct 73 ms 18244 KB Output is correct
42 Correct 73 ms 18272 KB Output is correct
43 Correct 72 ms 18208 KB Output is correct
44 Correct 75 ms 18148 KB Output is correct
45 Correct 133 ms 23096 KB Output is correct
46 Correct 93 ms 18488 KB Output is correct
47 Correct 79 ms 16376 KB Output is correct