# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
700654 | Polaris | Schools (IZhO13_school) | C++17 | 135 ms | 8200 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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
struct compare {
bool operator() (p a,p b) {
int ma = max(a.first,a.second);
int mb = max(b.first,b.second);
if(ma == mb)
return a.first+a.second < b.first+b.second;
return ma < mb;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N,M,S;
cin >> N >> M >> S;
priority_queue<p,vector<p>,compare> city;
for(int i=0; i<N; i++) {
int a,b;
cin >> a >> b;
city.push({a,b});
}
vector<int> music;
vector<int> sport;
int m2 = M;
int s2 = S;
while(!city.empty()) {
p f = city.top();
city.pop();
if(m2+s2 == 0)
break;
if(!m2) {
sport.push_back(f.second);
continue;
} else if(!s2) {
music.push_back(f.first);
continue;
}
p s = city.top();
if(f.first + s.second > f.second + s.first) {
m2--;
music.push_back(f.first);
} else if(f.second + s.first > f.first + s.second) {
s2--;
sport.push_back(f.second);
} else {
if(f.first > f.second) {
m2--;
music.push_back(f.first);
} else if(f.first < f.second) {
s2--;
sport.push_back(f.second);
} else {
if(m2 > s2) {
m2--;
music.push_back(f.first);
} else {
s2--;
sport.push_back(f.second);
}
}
}
}
sort(music.begin(),music.end(),greater<int>());
sort(sport.begin(),sport.end(),greater<int>());
ll ans = 0;
for(int i=0; i<M; i++) {
ans += music[i];
}
for(int i=0; i<S; i++) {
ans += sport[i];
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |