5133: USACO 2012 February Contest, Gold —— Problem 1. Cow Coupons
[Creator : ]
Description
Farmer John needs new cows! There are $N\ (1 \leq N \leq 50,000)$ cows for sale, and FJ has to spend no more than his budget of $M\ (1 \leq M \leq 10^{14})$ units of money . Cow i costs $P_i\ (1 \leq P_i \leq 10^9)$ money, but FJ has $K\ (1 \leq K \leq N)$ coupons, and when he uses a coupon on cow $i$, the cow costs $C_i\ (1 \leq C_i \leq P_i)$ instead.
FJ can only use one coupon per cow, of course.
What is the maximum number of cows FJ can afford?
FJ 准备买一些新奶牛。市场上有 $N$ 头奶牛,第 $i$ 头奶牛价格为 $P_i$。FJ 有 $K$ 张优惠券,使用优惠券购买第 $i$ 头奶牛时价格会降为 $C_i$,当然每头奶牛只能使用一次优惠券。FJ 想知道花不超过 $M$ 的钱最多可以买多少奶牛?
FJ can only use one coupon per cow, of course.
What is the maximum number of cows FJ can afford?
FJ 准备买一些新奶牛。市场上有 $N$ 头奶牛,第 $i$ 头奶牛价格为 $P_i$。FJ 有 $K$ 张优惠券,使用优惠券购买第 $i$ 头奶牛时价格会降为 $C_i$,当然每头奶牛只能使用一次优惠券。FJ 想知道花不超过 $M$ 的钱最多可以买多少奶牛?
Input
Line 1: Three space-separated integers: $N, K, M$.
Lines 2..N+1: Line i+1 contains two integers: $P_i$ and $C_i$.
Lines 2..N+1: Line i+1 contains two integers: $P_i$ and $C_i$.
Output
Line 1: A single integer, the maximum number of cows FJ can afford.
Constraints
$1 \le K \le N \le 5 \times 10^4$
$1 \le C_i \le P_i \le 10^9$
$1 \le M \le 10^{14}$
$1 \le C_i \le P_i \le 10^9$
$1 \le M \le 10^{14}$
Sample 1 Input
4 1 7
3 2
2 2
8 1
4 3
Sample 1 Output
3
FJ has 4 cows, 1 coupon, and a budget of 7.
FJ uses the coupon on cow 3 and buys cows 1, 2, and 3, for a total cost of 3 + 2 + 1 = 6.
FJ uses the coupon on cow 3 and buys cows 1, 2, and 3, for a total cost of 3 + 2 + 1 = 6.