#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |