Submission #299409

#TimeUsernameProblemLanguageResultExecution timeMemory
299409BruteforcemanPotatoes and fertilizers (LMIO19_bulves)C++11
30 / 100
647 ms11264 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector <int> pre (n + 1); for(int i = 1; i <= n; i++) { int a, b; cin >> a >> b; pre[i] = pre[i - 1] + a - b; } priority_queue <int> Q; long long base = 0; for(int i = 1; i <= n; i++) { if(pre[i] < 0) { base += -pre[i]; pre[i] = 0; } if(pre[i] > pre[n]) { base += pre[i] - pre[n]; pre[i] = pre[n]; } Q.push(pre[i]); Q.push(pre[i]); if(pre[i] < Q.top()) { base += Q.top() - pre[i]; } Q.pop(); } cout << base << endl; 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...