Submission #450318

#TimeUsernameProblemLanguageResultExecution timeMemory
450318cmoraxPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
403 ms8416 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int N; int fst = 0; // value of DP function at 0 priority_queue<int> points; // points where DP function changes slope signed main() { cin >> N; vector<int> dif(N+1); for (int i = 1; i <= N; ++i) { int a,b; cin >> a >> b; dif[i] = a-b+dif[i-1]; } assert(dif[N] >= 0); // assume solution exists for (int i = 1; i < N; ++i) { if (dif[i] < 0) fst -= dif[i], dif[i] = 0; points.push(dif[i]); points.push(dif[i]); fst += points.top() - dif[i]; points.pop(); } if(N == 1){ cout << 0 << endl; return 0; } int mult = 0; int last = points.top(); while(!points.empty()){ int at = points.top(); //cout << "/ " << at << " " << last << " " << mult << endl; if(at <= dif[N]){ fst += (last - dif[N]) * mult; break; } fst += (last - at) * mult; last = at; mult ++; points.pop(); } cout << fst << endl; }
#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...