作者:
炽热的
,
2022-06-11 16:23:45
,
所有人可见
,
阅读 68
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, pair<int, int>> PII;
const int N = 50010;
int n, k;
LL m;
bool st[N];
int main()
{
cin.tie(0)->sync_with_stdio(false);
priority_queue<PII, vector<PII>, greater<PII>> heap;
cin >> n >> k >> m;
for (int i = 1; i <= n; i ++ )
{
int a, b;
cin >> a >> b;
heap.push({a, {1, i}});
heap.push({b, {2, i}});
}
LL res = 0;
while (heap.size() && m > 0)
{
auto t = heap.top();
heap.pop();
LL w = t.x; int p = t.y.x, id = t.y.y;
if (m < w) break;
if (st[id] || (k == 0 && p == 2)) continue;
st[id] = true;
m -= w, res ++ ;
if (p == 2) k -- ;
}
cout << res << endl;
return 0;
}