#include <bits/stdc++.h>
#define f0(i, n) for(ll i(0); i < (n); i++)
#define f1(i, n) for(ll i(1); i <= n; i++)
using namespace std;
typedef long long ll;
const ll N = 300002;
ll n, m, s, a[N], b[N], id[N], ans1[N], ans2[N];
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> m >> s;
f1(i, n){
cin >> a[i] >> b[i];
id[i] = i;
}
sort(id + 1, id + n + 1, [&](ll a1, ll a2){
return a[a1] - b[a1] > a[a2] - b[a2];
});
priority_queue <ll, vector <ll>, greater <ll> > q;
f1(i, n){
if(q.size() < m){
ans1[i] = ans1[i - 1] + a[id[i]];
q.push(a[id[i]]);
}
else{
ll x = q.top();
q.pop();
q.push(a[id[i]]);
ans1[i] = ans1[i - 1] - x + a[id[i]];
}
}
while(q.size()) q.pop();
for(ll i = n; i >= 1; i--){
if(q.size() < s){
ans2[i] = ans2[i + 1] + b[id[i]];
q.push(b[id[i]]);
}
else{
ll x = q.top();
q.pop();ll
q.push(b[id[i]]);
ans2[i] = ans2[i + 1] - x + b[id[i]];
}
}
f1(i, n) ans1[i] = max(ans1[i], ans1[i - 1]);
for(ll i = n; i >= 1; i--) ans2[i] = max(ans2[i + 1], ans2[i]);
ll res = LLONG_MIN;
f1(i, n){
if(i >= m && n - i >= s) res = max(res, ans1[i] + ans2[i +1]);
}
cout << res;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:24:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(q.size() < m){
~~~~~~~~~^~~
school.cpp:37:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(q.size() < s){
~~~~~~~~~^~~
school.cpp:44:14: error: expected initializer before '.' token
q.push(b[id[i]]);
^