8431: Cow Coupons

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). Cow i costs P_i money (1 <= P_i <= 10^9), but FJ has K coupons (1 <= K <= N), and when he uses a coupon on cow i, the cow costs C_i instead (1 <= C_i <= P_i). FJ can only use one coupon per cow, of course.

What is the maximum number of cows FJ can afford?

FJ准备买一些新奶牛,市场上有N头奶牛(1<=N<=50000),第i头奶牛价格为Pi(1<=Pi<=10^9)。FJ有K张优惠券,使用优惠券购买第i头奶牛时价格会降为Ci(1<=Ci<=Pi),每头奶牛只能使用一次优惠券。FJ想知道花不超过M(1<=M<=10^14)的钱最多可以买多少奶牛?

输入格式

* Line 1: Three space-separated integers: N, K, and M.

* Lines 2..N+1: Line i+1 contains two integers: P_i and C_i.

第一行包含三个整数 N,K,M。



接下来 N 行,每行包含两个整数 Pi 和 Ci。



输出格式

* Line 1: A single integer, the maximum number of cows FJ can afford.



输出约翰能够买的奶牛最大数量。

输入样例 复制

4 1 7 
3 2 
2 2 
8 1 
4 3 

输出样例 复制

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.

约翰可以购买前三头牛,并且在第三头牛上使用优惠卷,这样所需花费为 3+2+1=6。

1≤N≤50000,

1≤M≤1014,

1≤Pi≤109,

1≤K≤N,

1≤Ci≤Pi