Submission #386301

#TimeUsernameProblemLanguageResultExecution timeMemory
386301johuthaPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
239 ms11252 KiB
#include <iostream> #include <vector> #include <queue> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; priority_queue<int> q; int pf = 0; int v0 = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; int d = a - b; pf += d; q.push(max(0ll, pf)); q.push(max(0ll, pf)); q.pop(); v0 += abs(pf); } int res = v0; while (q.size() > 0) { res -= min(q.top(), pf); q.pop(); } 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...