#include <bits/stdc++.h>
#define file "main"
#define maxn (int) 3e5 + 5
#define pii pair<int, int>
#define ll long long
#define gb(i, j) ((i >> j) & 1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define f first
#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
if(fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
}
int n, m, t;
pii a[maxn];
ll L[maxn], R[maxn];
void solve() {
cin >> n >> m >> t;
for(int i = 1; i <= n; i ++) cin >> a[i].f >> a[i].s;
sort(a + 1, a + n + 1, [](pii& x, pii& y) {
return x.f - y.f > x.s - y.s;
});
priority_queue<int> q;
ll sum = 0;
for(int i = 1; i <= n; i ++) {
q.push( -a[i].f ), sum += a[i].f;
if(q.size() < m) L[i] = -1e18;
else if(q.size() == m) L[i] = sum;
else {
ll val = -q.top(); q.pop();
sum -= val, L[i] = sum;
}
}
while(q.size()) q.pop();
sum = 0;
for(int i = n; i >= 1; i --) {
q.push( -a[i].s ), sum += a[i].s;
if(q.size() < t) R[i] = -1e18;
else if(q.size() == t) R[i] = sum;
else {
int val = -q.top(); q.pop();
sum -= val, R[i] = sum;
}
}
ll ans = 0;
for(int i = 1; i <= n; i ++) {
ans = max(ans, L[i] + R[i + 1]);
}
cout << ans;
}
int main()
{
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --) {
solve();
}
return 0;
}
Compilation message
school.cpp: In function 'void solve()':
school.cpp:45:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
45 | if(q.size() < m) L[i] = -1e18;
| ~~~~~~~~~^~~
school.cpp:46:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | else if(q.size() == m) L[i] = sum;
| ~~~~~~~~~^~~~
school.cpp:57:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
57 | if(q.size() < t) R[i] = -1e18;
| ~~~~~~~~~^~~
school.cpp:58:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
58 | else if(q.size() == t) R[i] = sum;
| ~~~~~~~~~^~~~
school.cpp: In function 'void iof()':
school.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4628 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
9 ms |
7260 KB |
Output is correct |
14 |
Correct |
17 ms |
7772 KB |
Output is correct |
15 |
Correct |
29 ms |
8364 KB |
Output is correct |
16 |
Correct |
37 ms |
9684 KB |
Output is correct |
17 |
Correct |
53 ms |
9940 KB |
Output is correct |
18 |
Correct |
57 ms |
10196 KB |
Output is correct |
19 |
Correct |
61 ms |
10708 KB |
Output is correct |
20 |
Correct |
66 ms |
11476 KB |
Output is correct |