/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 300005;
int n, m, s, k;
LL ans1,ans2;
pair<LL, LL> a[N];
multiset<LL> B;
int main()
{
cin >> n >> m >> s;
k = n - m - s;
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &a[i].first, &a[i].second);
sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) {
return a.first - a.second > b.first - b.second;
});
sort(a + 1, a + 1 + m+k, [](pair<LL, LL> a, pair<LL, LL> b) {
if (a.first != b.first)
return a.first < b.first;
return a.second > b.second;
});
reverse(a + 1, a + 1 + m+k);
for (int i = 1; i <= m; i++)
ans1 += a[i].first;
for (int i = 1; i <= n; i++)
swap(a[i].first, a[i].second);
sort(a + 1 + m, a + 1 + n);
for (int i = n; i > m + k; i--)
ans1 += a[i].first;
sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) {
return a.first - a.second > b.first - b.second;
});
swap(m,s);
sort(a + 1, a + 1 + m + k, [](pair<LL, LL> a, pair<LL, LL> b) {
if (a.first != b.first)
return a.first < b.first;
return a.second > b.second;
});
reverse(a + 1, a + 1 + m + k);
for (int i = 1; i <= m; i++)
ans2 += a[i].first;
for (int i = 1; i <= n; i++)
swap(a[i].first, a[i].second);
sort(a + 1 + m, a + 1 + n);
for (int i = n; i > m + k; i--)
ans2 += a[i].first;
cout << max(ans1,ans2) << endl;
return 0;
}
/*
3 1 1
100 0
100 50
0 20
4 1 1
100 0
550 500
500 550
0 100
3 1 1
100 0
500 550
0 100
*/
Compilation message
school.cpp: In function 'int main()':
school.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &a[i].first, &a[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
13 |
Incorrect |
23 ms |
1272 KB |
Output isn't correct |
14 |
Incorrect |
62 ms |
2552 KB |
Output isn't correct |
15 |
Correct |
137 ms |
4344 KB |
Output is correct |
16 |
Correct |
117 ms |
4704 KB |
Output is correct |
17 |
Incorrect |
134 ms |
5496 KB |
Output isn't correct |
18 |
Incorrect |
155 ms |
5792 KB |
Output isn't correct |
19 |
Incorrect |
166 ms |
6060 KB |
Output isn't correct |
20 |
Incorrect |
194 ms |
6776 KB |
Output isn't correct |