#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int sum[N][2];
int main(){
int n, m, s;
cin >> n >> m >> s;
vector<pair<int, pair<int, int>>> v1;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
v1.push_back({a - b, {a, b}});
}
sort(v1.rbegin(), v1.rend());
int tot = 0;
multiset<int> ms;
for(int i = 0; i < n; i++){
ms.insert(v1[i].second.first);
tot += v1[i].second.first;
if(ms.size() > m){
tot -= *ms.begin();
ms.erase(ms.begin());
}
sum[i + 1][0] = tot;
}
tot = 0;
ms.clear();
for(int i = n - 1; i >= 0; i--){
ms.insert(v1[i].second.second);
tot += v1[i].second.second;
if(ms.size() > s){
tot -= *ms.begin();
ms.erase(ms.begin());
}
sum[i + 1][1] = tot;
}
int ans = 0;
for(int i = m; i <= n - s; i++){
ans = max(ans, sum[i][0] + sum[i + 1][1]);
}
cout << ans << '\n';
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:24:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ms.size() > m){
~~~~~~~~~~^~~
school.cpp:35:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ms.size() > s){
~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
632 KB |
Output is correct |
8 |
Correct |
12 ms |
632 KB |
Output is correct |
9 |
Correct |
9 ms |
632 KB |
Output is correct |
10 |
Correct |
9 ms |
632 KB |
Output is correct |
11 |
Correct |
9 ms |
632 KB |
Output is correct |
12 |
Correct |
9 ms |
632 KB |
Output is correct |
13 |
Correct |
58 ms |
2904 KB |
Output is correct |
14 |
Correct |
112 ms |
3688 KB |
Output is correct |
15 |
Correct |
199 ms |
4808 KB |
Output is correct |
16 |
Incorrect |
320 ms |
12160 KB |
Output isn't correct |
17 |
Incorrect |
447 ms |
10468 KB |
Output isn't correct |
18 |
Incorrect |
414 ms |
10464 KB |
Output isn't correct |
19 |
Incorrect |
456 ms |
11364 KB |
Output isn't correct |
20 |
Incorrect |
530 ms |
12504 KB |
Output isn't correct |