Submission #717882

#TimeUsernameProblemLanguageResultExecution timeMemory
717882KLKLKPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
210 ms15212 KiB
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<queue> #define LL long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<LL> diff(n + 1); priority_queue<LL> Q; int a, b; LL res = 0; for (int i = 1; i <= n; ++i) { cin >> a >> b; diff[i] = a - b; diff[i] += diff[i - 1]; } for (int i = 1; i < n; ++i) { if (diff[i] < 0) { res -= diff[i]; diff[i] = 0; } else res += diff[i]; Q.push(diff[i]); Q.push(diff[i]); Q.pop(); } while (!Q.empty()) { LL x = Q.top(); Q.pop(); res -= min(x, diff[n]); } cout << res; }
#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...