#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
for (auto x: a) cout << x << " ";
cout << endl;
}
void solve(){
int n, m, s; cin >> n >> m >> s;
vector<vector<int>> music;
vector<vector<int>> sports;
vector<vector<int>> cities;
FOR(i,0,n){
int a, b; cin >> a >> b;
music.pb({a, b, i});
sports.pb({b, a, i});
cities.pb({a, b});
}
sort(all(music));
reverse(all(music));
sort(all(sports));
reverse(all(sports));
set<int> cm;
set<int> cs;
int ans = 0;
FOR(i,0,m){
cm.insert(music[i][2]);
ans += music[i][0];
}
FOR(i,0,s){
cs.insert(sports[i][2]);
ans += sports[i][0];
}
vector<int> common;
multiset<vector<int>, greater<vector<int>>> not_taken_m;
multiset<vector<int>, greater<vector<int>>> not_taken_s;
FOR(i,0,n){
if (cm.count(i) && cs.count(i)) common.pb(i);
if (!cm.count(i) && !cs.count(i)){
not_taken_m.insert(cities[i]);
not_taken_s.insert({cities[i][1], cities[i][0]});
}
}
// cout << ans << endl;
for (auto item: common){
if (not_taken_m.size()){
auto x = not_taken_m.begin();
// printVector(*x);
if (not_taken_s.size()){
auto y = not_taken_s.begin();
if ((*x)[0]-cities[item][0] > (*y)[0]-cities[item][1]){
ans += (*x)[0]-cities[item][0];
not_taken_m.erase(x);
}else{
ans += (*y)[0]-cities[item][1];
not_taken_s.erase(y);
}
continue;
}
ans += (*x)[0]-cities[item][0];
not_taken_m.erase(x);
}else{
auto y = not_taken_s.begin();
ans += (*y)[0]-cities[item][1];
not_taken_s.erase(y);
}
}
cout << ans << endl;
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
int t = 1; // cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
1616 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
1360 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
1616 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
1616 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
1616 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
1616 KB |
Output isn't correct |
13 |
Incorrect |
39 ms |
9068 KB |
Output isn't correct |
14 |
Incorrect |
109 ms |
25652 KB |
Output isn't correct |
15 |
Correct |
359 ms |
58164 KB |
Output is correct |
16 |
Incorrect |
234 ms |
49752 KB |
Output isn't correct |
17 |
Incorrect |
368 ms |
64052 KB |
Output isn't correct |
18 |
Incorrect |
418 ms |
71160 KB |
Output isn't correct |
19 |
Incorrect |
543 ms |
74556 KB |
Output isn't correct |
20 |
Incorrect |
653 ms |
90144 KB |
Output isn't correct |