Submission #474201

#TimeUsernameProblemLanguageResultExecution timeMemory
474201hoanghq2004Potatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
253 ms15220 KiB
#include <bits/stdc++.h> using namespace std; const int Nmax = 5e5 + 10; int n; long long dif[Nmax], ans; priority_queue <long long> opt; int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { int a, b; cin >> a >> b; dif[i] = dif[i - 1] + a - b; } for (int i = 1; i < n; ++i) { if (dif[i] < 0) ans -= dif[i], dif[i] = 0; opt.push(dif[i]), opt.push(dif[i]); opt.pop(); ans += dif[i]; } while (opt.size()) ans -= min(dif[n], opt.top()), opt.pop(); cout << ans; }
#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...