Submission #474199

#TimeUsernameProblemLanguageResultExecution timeMemory
474199hoanghq2004Potatoes and fertilizers (LMIO19_bulves)C++14
30 / 100
189 ms11200 KiB
#include <bits/stdc++.h> using namespace std; const int Nmax = 5e5 + 10; int n, dif[Nmax]; priority_queue <int> opt; long long ans; 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...