#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
int n, a, b;
cin >> n >> a >> b;
vector<pii> v(n);
for(auto &x : v) cin >> x.first >> x.second;
sort(v.rbegin(), v.rend());
ll pref=0, suf=0;
priority_queue<int> pq;
for(int i=0; i<a; i++) {
pref += v[i].first;
pq.push(v[i].second - v[i].first);
}
multiset<ll> ms;
for(int i=a; i<n; i++) ms.insert(v[i].second), suf += v[i].second;
while(ms.size() > b) {
suf -= *ms.begin();
ms.erase(ms.begin());
}
ll ans = pref + suf;
for(int i=a; i<a+b; i++) {
pref += v[i].first;
pq.push(v[i].second - v[i].first);
pref += pq.top(); pq.pop();
suf -= *ms.lower_bound(v[i].second);
ms.erase(ms.lower_bound(v[i].second));
ans = max(ans, pref + suf);
}
cout << ans << '\n';
return 0;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:32:21: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
32 | while(ms.size() > b) {
| ~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
528 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
14 ms |
1384 KB |
Output is correct |
14 |
Correct |
64 ms |
5200 KB |
Output is correct |
15 |
Correct |
108 ms |
10668 KB |
Output is correct |
16 |
Correct |
159 ms |
11236 KB |
Output is correct |
17 |
Correct |
141 ms |
11208 KB |
Output is correct |
18 |
Correct |
146 ms |
12396 KB |
Output is correct |
19 |
Correct |
165 ms |
13512 KB |
Output is correct |
20 |
Correct |
195 ms |
16076 KB |
Output is correct |