# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
682852 | smartmonky | Schools (IZhO13_school) | C++14 | 471 ms | 19592 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 = 3e5 + 1;
vector <int> a, b;
vector <pair <int,int> > vp;
multiset <int> sta, stb;
int lm, ls, ans, s, m, n;
void solve(){
for(int i = 0; i < n; i++){
if(!s && !m)break;
if(sta.find(vp[i].ff) != sta.end() && (m && !s || m && abs(vp[i].ff - a[lm]) >= abs(vp[i].ss - b[ls]) || stb.find(vp[i].ss) == stb.end())){
//cout <<"1 " << vp[i].ff << endl;
ans += vp[i].ff;
if(sta.find(vp[i].ff) != sta.end())
sta.erase(sta.find(vp[i].ff));
if(stb.find(vp[i].ss) != stb.end()){
stb.erase(stb.find(vp[i].ss));
stb.insert(b[ls]);
}
ls++;
m--;
}else if(stb.find(vp[i].ss) != stb.end() && (!m && s || s && abs(vp[i].ff - a[lm]) <= abs(vp[i].ss - b[ls]) || sta.find(vp[i].ff) == sta.end())){
//cout <<"2 " << vp[i].ss << endl;
ans += vp[i].ss;
if(sta.find(vp[i].ff) != sta.end()){
sta.erase(sta.find(vp[i].ff));
sta.insert(a[lm]);
}
if(stb.find(vp[i].ss) != sta.end())
stb.erase(stb.find(vp[i].ss));
lm++;
s--;
}
}
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> s;
vp.resize(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(rall(a));
sort(rall(b));
for(int i = 0; i < m; i++)
sta.insert(a[i]);
for(int i = 0; i < s; i++)
stb.insert(b[i]);
lm = m, ls = s;
for(int i = 0; i < 10; i++){
sort(rall(vp));
solve();
for(int i = 0; i < n; i++)swap(vp[i].ff, vp[i].ss);
solve();
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |