Submission #798692

#TimeUsernameProblemLanguageResultExecution timeMemory
798692abcvuitunggioPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
114 ms16296 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n,a[500001],b[500001],d[500001],res; priority_queue <int> q; int32_t main(){ ios_base::sync_with_stdio(NULL);cin.tie(nullptr); cin >> n; for (int i=1;i<=n;i++){ cin >> a[i] >> b[i]; d[i]=d[i-1]+a[i]-b[i]; } for (int i=1;i<n;i++){ res+=max(-d[i],0LL)+max(d[i]-d[n],0LL); d[i]=min(max(d[i],0LL),d[n]); q.push(d[i]); q.push(d[i]); res+=q.top()-d[i]; q.pop(); } cout << res; }
#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...