# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
700654 | Polaris | 학교 설립 (IZhO13_school) | C++17 | 135 ms | 8200 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |