This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |