#include <bits/stdc++.h>
#define N 300005
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
ll used[N], n, m, s;
pair<pii, ll> v[N];
bool cmp4(pair<pii, ll> a, pair<pii, ll> b){
return a.f.f > b.f.f;
}
bool cmp3(pair<pii, ll> a, pair<pii, ll> b){
return a.f.s > b.f.s;
}
bool cmp2(pair<pii, ll> a, pair<pii, ll> b){
return a.f.s - a.f.f > b.f.s - b.f.f;
}
bool cmp(pair<pii, ll> a, pair<pii, ll> b){
return a.f.f - a.f.s > b.f.f - b.f.s;
}
ll solve1()
{
ll ans = 0;
sort(v + 1, v + n + 1, cmp);
for(int i = 1; i <= m; i++) ans += v[i].f.f, used[v[i].s] = 1;
sort(v + 1, v + n + 1, cmp3);
for(int i = 1, cnt = 1; i <= n && cnt <= s; i++) if(!used[v[i].s]) cnt ++, ans += v[i].f.s;
return ans;
}
ll solve2()
{
ll ans = 0;
memset(used, 0, sizeof used);
sort(v + 1, v + n + 1, cmp2);
for(int i = 1; i <= s; i++) ans += v[i].f.s, used[v[i].s] = 1;
sort(v + 1, v + n + 1, cmp4);
for(int i = 1, cnt = 1; i <= n && cnt <= m; i++) if(!used[v[i].s]) cnt ++, ans += v[i].f.f;
return ans;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m>>s;
for(int i = 1; i <= n; i++) cin>>v[i].f.f>>v[i].f.s, v[i].s = i;
cout<<max(solve1(), solve2())<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Output is correct |
2 |
Correct |
3 ms |
2788 KB |
Output is correct |
3 |
Correct |
3 ms |
2788 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2788 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |