Submission #750666

#TimeUsernameProblemLanguageResultExecution timeMemory
750666findingFishPotatoes and fertilizers (LMIO19_bulves)C++17
20 / 100
7 ms1368 KiB
#include "bits/stdc++.h" using namespace std; const int N = 5e5 + 5; int a[N], b[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int res = 0; for(int i=1;i<=n;i++){ cin >> a[i] >> b[i]; a[i] -= b[i]; a[i] += a[i-1]; } int mx = a[n]; assert(0 <= mx); for(int i=1;i<=n;i++){ if(a[i] < 0){ res -= a[i]; a[i] = 0; } if(a[i] > mx){ res += (a[i] - mx); a[i] = mx; } } priority_queue<int> q; for(int i=1;i<=n;i++){ q.push(a[i]); if(a[i] < q.top()){ res += (q.top() - a[i]); q.pop(); q.push(a[i]); } } 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...