#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("TAMCAM.inp", "r", stdin);
// freopen("TAMCAM.out", "w", stdout);
int k, n, m;
cin >> k >> n >> m;
vector<pair<int, int>> a(k);
for(pair<int, int> &o: a){
cin >> o.first >> o.second;
}
sort(a.begin(), a.end(), [&](pair<int, int> a, pair<int, int> b){
return a.second - a.first < b.second - b.first;
});
vector<ll> L(k + 3, 0), R(k + 3, 0);
{
priority_queue<ll, vector<ll>, greater<ll>> pq;
ll cur = 0;
for(int i=1; i<=k; i++){
cur += 1LL * a[i - 1].first;
pq.push(a[i - 1].first);
if((int)pq.size() > n){
cur -= pq.top();
pq.pop();
}
L[i] = cur;
}
}
{
priority_queue<ll, vector<ll>, greater<ll>> pq;
ll cur = 0;
for(int i=k; i>=1; i--){
cur += 1LL * a[i - 1].second;
pq.push(a[i - 1].second);
if((int)pq.size() > m){
cur -= pq.top();
pq.pop();
}
R[i] = cur;
}
}
ll ans = 0;
for(int i=n; i<=k-m; i++){
ans = max(ans, L[i] + R[i + 1]);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
9 ms |
2016 KB |
Output is correct |
14 |
Correct |
21 ms |
3344 KB |
Output is correct |
15 |
Correct |
41 ms |
6020 KB |
Output is correct |
16 |
Correct |
49 ms |
8624 KB |
Output is correct |
17 |
Correct |
68 ms |
9796 KB |
Output is correct |
18 |
Correct |
70 ms |
10416 KB |
Output is correct |
19 |
Correct |
76 ms |
11344 KB |
Output is correct |
20 |
Correct |
97 ms |
12772 KB |
Output is correct |