#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Function {
multiset<int> s;
int k, p;
Function(int a, int b) { k = a, p = b; }
void reset(int a, int b) { s.clear(), k = a, p = b; }
void prefix() {
if (k <= 0)
return;
if (s.size() < k)
assert(0);
auto it = s.end();
int c = k;
while (c--) {
it--;
k--, p += *it;
s.erase(it);
}
}
void merge(Function x) {
for (auto ele : x.s)
s.insert(ele);
k += x.k, p += x.p;
}
};
int A[500010], B[500010];
void get() {
int n, i, x;
cin >> n;
for (i = 1; i <= n; i++)
cin >> A[i] >> B[i], A[i] += A[i - 1], B[i] += B[i - 1];
Function a(0, 0);
Function h(0, 0);
for (i = 1; i < n; i++) {
x = A[i] - B[i];
h.reset(1, -x), h.s.insert(x), h.s.insert(x);
a.merge(h);
a.prefix();
}
cout << a.p;
return;
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(NULL);
int T;
T = 1;
while (T--)
get();
return 0;
}
Compilation message
bulves.cpp: In member function 'void Function::prefix()':
bulves.cpp:12:16: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
12 | if (s.size() < k)
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |