Submission #203279

#TimeUsernameProblemLanguageResultExecution timeMemory
203279dolphingarlicPotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
189 ms15336 KiB
#include <bits/stdc++.h> using namespace std; long long c[500001], ans = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { long long a, b; cin >> a >> b; c[i] = c[i - 1] + a - b; } priority_queue<long long> pq; for (int i = 1; i <= n; i++) { if (c[i] > c[n]) { ans += c[i] - c[n]; c[i] = c[n]; } else if (c[i] < 0) { ans -= c[i]; c[i] = 0; } pq.push(c[i]); pq.push(c[i]); ans += pq.top() - c[i]; pq.pop(); } cout << ans; 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...