#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m, s;
cin >> n >> m >> s;
vector<pair<int, int>> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i].first >> c[i].second;
}
vector<array<int, 3>> cities;
cities.reserve(n);
for (int i = 0; i < n; i++) {
int a = c[i].first, b = c[i].second;
cities.push_back({max(a, b), a, b});
}
sort(cities.begin(), cities.end(), [](auto &l, auto &r) {
return l[0] > r[0];
});
int total = m + s;
vector<array<int, 3>> sel(cities.begin(), cities.begin() + total);
int m_sel = 0, s_sel = 0;
long long sum = 0;
vector<long long> mp_diff, sp_diff;
for (auto &city : sel) {
int a = city[1], b = city[2];
if (a >= b) {
m_sel++;
sum += a;
mp_diff.push_back(a - b);
} else {
s_sel++;
sum += b;
sp_diff.push_back(b - a);
}
}
if (m_sel > m) {
int flip = m_sel - m;
sort(mp_diff.begin(), mp_diff.end());
for (int i = 0; i < flip; i++) {
sum -= mp_diff[i];
}
} else if (s_sel > s) {
int flip = s_sel - s;
sort(sp_diff.begin(), sp_diff.end());
for (int i = 0; i < flip; i++) {
sum -= sp_diff[i];
}
}
cout << sum << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |