#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long 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());
long long tot = 0;
multiset<long long> 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;
}
long long 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 |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 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 |
9 ms |
756 KB |
Output is correct |
9 |
Correct |
9 ms |
788 KB |
Output is correct |
10 |
Correct |
9 ms |
760 KB |
Output is correct |
11 |
Correct |
9 ms |
632 KB |
Output is correct |
12 |
Correct |
9 ms |
760 KB |
Output is correct |
13 |
Correct |
57 ms |
3052 KB |
Output is correct |
14 |
Correct |
111 ms |
3740 KB |
Output is correct |
15 |
Correct |
201 ms |
5324 KB |
Output is correct |
16 |
Correct |
327 ms |
13084 KB |
Output is correct |
17 |
Correct |
540 ms |
11620 KB |
Output is correct |
18 |
Correct |
413 ms |
11600 KB |
Output is correct |
19 |
Correct |
452 ms |
12652 KB |
Output is correct |
20 |
Correct |
522 ms |
14276 KB |
Output is correct |