8437: Gifts

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

题目描述

Farmer John wants to give gifts to his N (1 <= N <= 1000) cows, using his total budget of B (1 <= B <= 1,000,000,000) units of money. Cow i requests a gift with a price of P(i) units, and a shipping cost of S(i) units (so the total cost would be P(i)+S(i) for FJ to order this gift). FJ has a special coupon that he can use to order one gift of his choosing at only half its normal price. If FJ uses the coupon for cow i, he therefore would only need to pay P(i)/2+S(i) for that cow's gift. Conveniently, the P(i)'s are all even numbers. Please help FJ determine the maximum number of cows to whom he can afford to give gifts.

农夫约翰想给他的 N 头奶牛购买礼物,但是他的预算只有 B 元。



奶牛 i 希望获得的礼物的价格为 Pi,运输成本为 Si,也就是说约翰要帮奶牛 i 买礼物,共需花费 Pi+Si 元钱。



约翰有一张特殊的优惠券,如果使用该优惠券来订购一份礼物,那么该礼物的价格会变为只有正常价格的一半。



如果约翰用该优惠券给奶牛 i 买礼物,那么他只需要支付 ⌊Pi/2⌋+Si 元钱。



请帮助约翰确定他最多可以给多少头奶牛购买礼物。

输入格式

第一行包含两个整数 N 和 B。



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

输出格式



输出约翰可以购买礼物的奶牛最大数量。

输入样例 复制

5 24
4 2
2 0
8 1
6 3
12 5

输出样例 复制

4

数据范围与提示

1≤N≤1000,

1≤B≤109,

0≤Pi,Si≤109

样例解释

一种最佳方案是约翰给前 4 头奶牛购买礼物,在给第 3 头奶牛购买礼物时使用优惠券。