#P2983. [USACO10FEB] Chocolate Buying S

[USACO10FEB] Chocolate Buying S

题目描述

Bessie and the herd love chocolate so Farmer John is buying them some.

The Bovine Chocolate Store features N(1N100,000)N (1 \le N \le 100,000) kinds of chocolate in essentially unlimited quantities. Each type i of chocolate has price Pi(1Pi1018)P_i (1 \le P_i \le 10^{18}) per piece and there are Ci(1Ci1018)C_i (1 \le C_i \le 10^{18}) cows that want that type of chocolate.

Farmer John has a budget of B(1B1018)B (1 \le B \le 10^{18}) that he can spend on chocolates for the cows. What is the maximum number of cows that he can satisfy? All cows only want one type of chocolate, and will be satisfied only by that type.

Consider an example where FJ has 5050 to spend on 55 different types of chocolate. A total of eleven cows have various chocolate preferences:

Chocolate_Type Per_Chocolate_Cost Cows_preferring_this_type
11 55 33
22 11
33 1010 44
44 77 22
55 6060 11

Obviously, FJ can't purchase chocolate type 55, since he doesn't have enough money. Even if it cost only 5050, it's a counterproductive purchase since only one cow would be satisfied.

Looking at the chocolates start at the less expensive ones, he can purchase 11 chocolate of type 22 for 1×11 \times 1 leaving 501=4950-1=49, then purchase 33 chocolate of type 11 for 3×53 \times 5 leaving 4915=3449-15=34, then purchase 22 chocolate of type 44 for 2×72 \times 7 leaving 3414=2034-14=20, then purchase 22 chocolate of type 33 for 2×102 \times 10 leaving 2020=020-20=0.

He would thus satisfy 1+3+2+2=81 + 3 + 2 + 2 = 8 cows.

输入格式

Line 11: Two space separated integers: NN and BB.

Lines 2N+12\ldots N+1: Line ii contains two space separated integers defining chocolate type ii: PiP_i and CiC_i.

输出格式

Line 11: A single integer that is the maximum number of cows that Farmer John can satisfy.

题目大意

贝茜和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们。奶牛巧克力专卖店里有 NN 种巧克力,每种巧克力的数量都是无限多的。

每头奶牛只喜欢一种巧克力,调查显示,有 CiC_i 头奶牛喜欢第 ii 种巧克力,这种巧克力的售价是 PiP_i

约翰手上有 BB 元预算,怎样用这些钱让尽量多的奶牛高兴呢?

5 50 
5 3 
1 1 
10 4 
7 2 
60 1 

8