# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
682809 | smartmonky | Schools (IZhO13_school) | C++14 | 125 ms | 11956 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>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
using namespace std;
const int N = 1e5 + 1;
bool comp(pair <int,int> a, pair <int,int> b){
return max(a.ff,a.ss) > max(b.ff,b.ss);
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, s;
cin >> n >> m >> s;
vector <int> a, b;
vector <pair <int,int> > vp(n);
for(int i = 0; i < n; i++){
cin >> vp[i].ff >> vp[i].ss;
a.pb(vp[i].ff);
b.pb(vp[i].ss);
}
sort(all(vp), comp);
sort(rall(a));
sort(rall(b));
int lm = m, ls = s;
int ans = 0;
//swap(s, m);
for(int i = 0; i < n; i++){
if(!(vp[i].ff >= a[lm - 1] || vp[i].ss >= b[ls - 1]) || !s && !m)continue;
if(vp[i].ff >= a[lm - 1] && (m && !s || m && abs(vp[i].ff - a[lm]) >= abs(vp[i].ss - b[ls]))){
ans += vp[i].ff;
ls++;
//cout <<"1 " << vp[i].ff << endl;
m--;
}else if(vp[i].ss >= b[ls - 1] && (!m && s || s && abs(vp[i].ff - a[lm]) <= abs(vp[i].ss - b[ls]))){
ans += vp[i].ss;
lm++;
s--;
//cout <<"2 " << vp[i].ss << endl;
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |