# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085047 | Sunbae | Schools (IZhO13_school) | C++17 | 156 ms | 7200 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
#define z exit(0)
#define mp make_pair
#define F first
#define S second
using namespace std;
using pii = pair<int,int>;
const int N = 3e5 + 5;
pii a[N];
int v[N];
bool cmp1(int i, int j){
return mp(a[i].F - a[i].S, a[i].S) > mp(a[j].F - a[j].S, a[j].S);
}
bool cmp2(int i, int j){
return mp(a[i].S - a[i].F, a[i].F) > mp(a[j].S - a[j].F, a[j].F);
}
bool cmp11(int i, int j){
return a[i].S > a[j].S;
}
bool cmp22(int i, int j){
return a[i].F > a[j].F;
}
signed main(){
int n, m[2]; scanf("%d %d %d", &n, m, m+1);
for(int i = 0, x, y; i<n; ++i){
scanf("%d %d", &x, &y);
a[i] = mp(x, y);
}
for(int i = 0; i<n; ++i) v[i] = i;
sort(v, v+n, cmp1);
ll sum = 0;
int idx = 0;
for(int cnt = 0; cnt < m[0]; ++cnt, ++idx) sum += a[v[idx]].F;
sort(v+idx, v+n, cmp11);
for(int cnt = 0; cnt < m[1]; ++cnt, ++idx) sum += a[v[idx]].S;
ll mx = sum;
//
sort(v, v+n, cmp2);
sum = idx = 0;
for(int cnt = 0; cnt < m[1]; ++cnt, ++idx) sum += a[v[idx]].S;
sort(v+idx, v+n, cmp22);
for(int cnt = 0; cnt < m[0]; ++cnt, ++idx) sum += a[v[idx]].F;
mx = max(mx, sum);
printf("%lld", mx);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |