Submission #393839

#TimeUsernameProblemLanguageResultExecution timeMemory
393839ronnithPotatoes and fertilizers (LMIO19_bulves)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; const int N = (int)5e5; int n, a[N], b[N]; long long d[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 0;i < n;i ++) { cin >> a[i] >> b[i]; d[i] = a[i]-b[i] + (i!=1?d[i-1]:0); } priority_queue<int> pq; pq.push(d[0]); long long ans = 0; for(int i = 1;i < n;i ++) { pq.push(d[i]); pq.push(d[i]); ans += pq.top()-d[i]; pq.pop(); } cout << ans << '\n'; return 0; }
#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...