Submission #715951

#TimeUsernameProblemLanguageResultExecution timeMemory
715951amunduzbaevPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
143 ms19116 KiB
#include "bits/stdc++.h" using namespace std; #define ar array typedef long long ll; #define int ll 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...