# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
473507 | 2021-09-15T15:49:37 Z | Fgdxx | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 541 ms | 66036 KB |
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; priority_queue<int, vector<int>, greater<int>> q; for(int i = 0; i < 30*n; i++)q.push(0); long long shift = 0; long long val = 0; for(int i = 0; i < n; i++){ int a, b; cin>>a>>b; long long x1 = q.top(); q.pop(); long long x2 = q.top();//pochodna na x1, x2 0 wiec x1 niepotrzebne shift += a - b; x2 += shift; if(x2 < 0){//w przeciwnym wypadku nic sie nie dzieje val -= x2; } q.push(-shift); q.push(-shift); } //cout<<q.top() + shift<<" "<<val<<"\n\n"; //obliczamy roznice miedzy 0 a tam gdzie znamy val long long diff = 0; long long slope = -1; long long x = q.top()+shift; if(x > 0){ diff = x; }else{ while(x < 0){ q.pop(); slope++; long long newX = min(q.top()+shift, 0ll); diff += slope * (newX - x); x = newX; } } cout<<(val + diff); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 2 ms | 840 KB | Output is correct |
3 | Correct | 3 ms | 960 KB | Output is correct |
4 | Correct | 46 ms | 8632 KB | Output is correct |
5 | Correct | 98 ms | 16796 KB | Output is correct |
6 | Correct | 314 ms | 33188 KB | Output is correct |
7 | Correct | 541 ms | 66036 KB | Output is correct |
8 | Incorrect | 478 ms | 66020 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 2 ms | 840 KB | Output is correct |
3 | Correct | 3 ms | 960 KB | Output is correct |
4 | Correct | 46 ms | 8632 KB | Output is correct |
5 | Correct | 98 ms | 16796 KB | Output is correct |
6 | Correct | 314 ms | 33188 KB | Output is correct |
7 | Correct | 541 ms | 66036 KB | Output is correct |
8 | Incorrect | 478 ms | 66020 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 2 ms | 840 KB | Output is correct |
3 | Correct | 1 ms | 292 KB | Output is correct |
4 | Correct | 1 ms | 460 KB | Output is correct |
5 | Correct | 2 ms | 588 KB | Output is correct |
6 | Correct | 3 ms | 840 KB | Output is correct |
7 | Correct | 3 ms | 936 KB | Output is correct |
8 | Correct | 3 ms | 840 KB | Output is correct |
9 | Correct | 3 ms | 840 KB | Output is correct |
10 | Correct | 3 ms | 932 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 2 ms | 840 KB | Output is correct |
3 | Correct | 3 ms | 960 KB | Output is correct |
4 | Correct | 1 ms | 292 KB | Output is correct |
5 | Correct | 1 ms | 460 KB | Output is correct |
6 | Correct | 2 ms | 588 KB | Output is correct |
7 | Correct | 3 ms | 840 KB | Output is correct |
8 | Correct | 3 ms | 936 KB | Output is correct |
9 | Correct | 3 ms | 840 KB | Output is correct |
10 | Correct | 3 ms | 840 KB | Output is correct |
11 | Correct | 3 ms | 932 KB | Output is correct |
12 | Correct | 3 ms | 588 KB | Output is correct |
13 | Correct | 4 ms | 936 KB | Output is correct |
14 | Correct | 4 ms | 968 KB | Output is correct |
15 | Correct | 3 ms | 968 KB | Output is correct |
16 | Correct | 4 ms | 968 KB | Output is correct |
17 | Correct | 3 ms | 940 KB | Output is correct |
18 | Correct | 4 ms | 928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 2 ms | 840 KB | Output is correct |
3 | Correct | 3 ms | 960 KB | Output is correct |
4 | Correct | 1 ms | 292 KB | Output is correct |
5 | Correct | 1 ms | 460 KB | Output is correct |
6 | Correct | 2 ms | 588 KB | Output is correct |
7 | Correct | 3 ms | 840 KB | Output is correct |
8 | Correct | 3 ms | 936 KB | Output is correct |
9 | Correct | 3 ms | 840 KB | Output is correct |
10 | Correct | 3 ms | 840 KB | Output is correct |
11 | Correct | 46 ms | 8632 KB | Output is correct |
12 | Correct | 98 ms | 16796 KB | Output is correct |
13 | Correct | 314 ms | 33188 KB | Output is correct |
14 | Correct | 541 ms | 66036 KB | Output is correct |
15 | Incorrect | 478 ms | 66020 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |