Submission #740743

#TimeUsernameProblemLanguageResultExecution timeMemory
740743Prieved1Potatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
360 ms15176 KiB
#include<bits/stdc++.h> using namespace std; int main () { int n; cin >> n; int a[n], b[n]; long long res=0; long long d=0, dd=0; priority_queue<long long> pq; for(int i = 0;i<n;i++) { cin >> a[i] >> b[i]; dd+=a[i]-b[i]; } for(int i = 0;i<n;i++) { d+=a[i]-b[i]; long long c=d; if(c<0) { res-=c; c=0; } if(c>dd) { res+=c-dd; c=dd; } // cerr << c << " " << d << endl; pq.push(c); if(pq.top()!=c) { res+=pq.top()-c; pq.pop(); pq.push(c); } } cout << res << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...