#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; ){
q.push(-a[i][0]);
sum += a[i][0];
while((int)q.size() > m) sum += q.top(), q.pop();
ans = max(ans, sum + a[i-1][1]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
452 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
14 ms |
1624 KB |
Output is correct |
14 |
Correct |
32 ms |
2792 KB |
Output is correct |
15 |
Correct |
59 ms |
4560 KB |
Output is correct |
16 |
Correct |
73 ms |
7184 KB |
Output is correct |
17 |
Correct |
89 ms |
7992 KB |
Output is correct |
18 |
Correct |
98 ms |
8528 KB |
Output is correct |
19 |
Correct |
106 ms |
9032 KB |
Output is correct |
20 |
Correct |
121 ms |
10164 KB |
Output is correct |