Submission #566065

#TimeUsernameProblemLanguageResultExecution timeMemory
566065lorenzoferrariPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
4 ms468 KiB
#include <bits/stdc++.h> using namespace std; using LL = long long; struct SlopeTrick { LL inc = 0; multiset<LL> s; void insert(LL x){ s.insert(x - inc); } void pop(){ s.erase(s.begin()); } void increase(LL v) { inc += v; } LL getmin() { return *s.begin() + inc; } multiset<int> get() { multiset<int> ans; for (LL x : s) ans.insert(x + inc); return ans; } }; int main() { #ifdef LORENZO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; SlopeTrick st; LL sum = 0; LL ans = 0; for (int i = 0, a, b; i < n; ++i) { cin >> a >> b; int v = b - a; sum += v; st.increase(v); st.insert(v); st.insert(v); ans += v - st.getmin(); st.pop(); } cout << ans << "\n"; }
#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...