#include <bits/stdc++.h>
using namespace std;
struct C {
int a, b;
long long d;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m, s;
cin >> n >> m >> s;
vector<C> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i].a >> v[i].b;
v[i].d = (long long)v[i].a - v[i].b;
}
sort(v.begin(), v.end(), [&](const C &x, const C &y) {
return x.d != y.d ? x.d > y.d : x.a > y.a;
});
long long sa = 0, sb = 0;
for (int i = 0; i < m; i++) sa += v[i].a;
vector<int> r;
for (int i = m; i < n; i++) r.push_back(v[i].b);
if (s > 0) {
if (s >= (int)r.size()) {
for (auto x : r) sb += x;
} else {
nth_element(r.begin(), r.begin() + s, r.end(), greater<int>());
for (int i = 0; i < s; i++) sb += r[i];
}
}
cout << sa + sb;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |