#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 5e5 + 5;
typedef long long LL;
struct SlopeTrick {
LL a, b;
priority_queue <LL> *H;
SlopeTrick () {
a = b = 0;
H = new priority_queue<LL>;
}
SlopeTrick operator += (SlopeTrick other) {
a += other.a;
b += other.b;
if (H->size() > other.H->size())
swap(H, other.H);
while (!other.H->empty()) {
H->push(other.H->top());
other.H->pop();
}
while (a > 0) {
-- a;
b += H->top();
H->pop();
}
return *this;
}
SlopeTrick Evaluate () {
while (a > 0) {
-- a;
b += H->top();
H->pop();
}
return *this;
}
};
int N;
LL D[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
for (int i = 1; i <= N; ++ i ) {
LL A, B;
cin >> A >> B;
D[i] = D[i-1] + A - B;
}
}
void Solve () {
SlopeTrick ans;
for (int i = 1; i < N; ++ i ) {
SlopeTrick aux;
aux.a = 1;
aux.b = -D[i];
if (D[i] < 0) D[i] = 0;
aux.H->push(D[i]);
aux.H->push(D[i]);
ans += aux;
}
ans.Evaluate();
cout << ans.b << '\n';
}
int main () {
Read();
Solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |