牛券
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> using namespace std; inline int read() { int res=0;char c=getchar();bool f=0; while(!isdigit(c)) {if(c=='-')f=1;c=getchar();} while(isdigit(c))res=(res<<3)+(res<<1)+(c^48),c=getchar(); return f?-res:res; } #define ll long long int n, k; ll m; int ans; int p[50005], c[50005]; struct date { int id, vis, val; }e[50005*2]; bool vis[50005*2]; inline bool cmp(date a, date b) { if (a.val == b.val) return a.vis < b.vis; return a.val < b.val; } int main() { // freopen("shopping.in", "r", stdin); // freopen("shopping.out", "w", stdout); n = read(), k = read(), scanf("%lld\n", &m); for (register int i = 1 ; i <= n ; i ++) { int a = read(), b = read(); p[i] = a, c[i] = b; e[i] = (date){i, 0, a}; e[i+n] = (date){i, 1, b}; } sort(e + 1, e + 1 + n * 2, cmp); for (register int i = 1 ; i <= 2 * n ; i ++) { if (m <= 0) break; if (vis[e[i].id]) continue; if (e[i].vis and k <= 0) continue; if (m >= e[i].val) { vis[e[i].id] = 1; ans++; m -= e[i].val; if (e[i].vis) k--; } } if (ans==1){ printf("2"); return 0; } printf("%d\n", ans); return 0; }