#P4377. [USACO18OPEN] Talent Show G

[USACO18OPEN] Talent Show G

Description

Farmer John is taking his nn cows, conveniently numbered 1n1 \ldots n, to the agricultural fair to participate in the annual Talent Show. His ii-th cow has weight wiw_i and talent tit_i, both integers.

Upon arrival, Farmer John is alarmed by the new rules for this year's show:

(1) A participating group of cows must have total weight at least WW (this is to ensure strong teams compete, not just a single strong cow), and

(2) The group with the maximum ratio of total talent to total weight wins.

FJ notices that the total weight of all his cows is at least WW, so he can send a team that satisfies rule (1). Help him determine the best achievable ratio of total talent to total weight among such teams.

Input Format

The first line contains two integers, the number of cows nn and the weight threshold WW.

Lines 22 through (n+1)(n+1) each contain two integers. The integers on line (i+1)(i+1) give the weight wiw_i and talent tit_i of the ii-th cow.

Output Format

Compute the maximum possible ratio of total talent to total weight for a group of cows whose total weight is at least WW.

If your answer is AA, output the value of 1000A1000A rounded down to an integer (i.e., take the floor; when a number is not an integer, flooring removes all fractional digits).

Note that if the exact answer is an integer xx, your program may produce xϵx - \epsilon due to floating-point precision and, after flooring, incorrectly output x1x - 1. In this case, you can add a tiny value before flooring, e.g., xx+10kx \gets x + 10^{-k}, to avoid this issue.

3 15
20 21
10 11
30 31
1066

Hint

Sample Explanation

In this example, the globally best ratio of talent to weight would be achieved by using only the cow with talent 1111 and weight 1010. However, since we need at least 1515 units of weight, the optimal solution is to use that cow together with the cow of talent 2121 and weight 2020. The resulting ratio is 11+2110+20=3230=1.0666\frac{11+21}{10+20}=\frac{32}{30} = 1.0666\dots, which becomes 10661066 after multiplying by 10001000 and taking the floor.

Constraints

For all testdata, it is guaranteed that 1n2501 \leq n \leq 250, 1W10001 \leq W \leq 1000, 1wi1061 \leq w_i \leq 10^6, and 1ti1031 \leq t_i \leq 10^3.

Translated by ChatGPT 5