https://www.acmicpc.net/problem/25391
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL)
#define ll long long
const char en = '\n';
const int INF = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
struct s {
	int a, b;
	bool c;
};
bool cmp_1(s x, s y) {
	if (x.a == y.a) return x.b > y.b;
	return x.a > y.a;
}
bool cmp_2(s x, s y) {
	if (x.b == y.b) return x.a > y.a;
	return x.b > y.b;
}
int main(void) {
	fast;
	int n, m, k; cin >> n >> m >> k;
	vector<s> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i].a >> v[i].b;
		v[i].c = false;
	}
	sort(v.begin(), v.end(), cmp_2);
	ll ans = 0;
	for (int i = 0; i < k; ++i) v[i].c = true;
	sort(v.begin(), v.end(), cmp_1);
	for (int i = 0; m; ++i) {
		if (!v[i].c) v[i].c = true, m--;
	}
	for (int i = 0; i < n; ++i) {
		if (v[i].c) ans += v[i].a;
	}
	cout << ans << en;
	return 0;
}