#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
int n, m, s, sum, ans;
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> s;
array<int, 2> a[n];
for(auto &i : a) cin >> i[0] >> i[1];
sort(a, a+n, [&](auto &i, auto &j){
return i[0] - i[1] < j[0] - j[1];
});
priority_queue<int> q;
for(int i=0; i<n; ++i){
q.push(-a[i][1]);
sum += a[i][1];
while((int)q.size() > s) sum += q.top(), q.pop();
a[i][1] = sum;
}
priority_queue<int> ().swap(q);
sum = 0;
for(int i=n; --i>=0; ){
q.push(-a[i][0]);
sum += a[i][0];
while((int)q.size() > m) sum += q.top(), q.pop();
ans = max(ans, sum + (i ? a[i-1][1] : 0LL));
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
13 ms |
1232 KB |
Output is correct |
14 |
Correct |
32 ms |
1900 KB |
Output is correct |
15 |
Correct |
59 ms |
2776 KB |
Output is correct |
16 |
Correct |
73 ms |
5280 KB |
Output is correct |
17 |
Correct |
87 ms |
5304 KB |
Output is correct |
18 |
Correct |
98 ms |
5724 KB |
Output is correct |
19 |
Correct |
108 ms |
6048 KB |
Output is correct |
20 |
Correct |
122 ms |
6740 KB |
Output is correct |