#P4377. [USACO18OPEN] Talent Show G
[USACO18OPEN] Talent Show G
Description
Farmer John is taking his cows, conveniently numbered , to the agricultural fair to participate in the annual Talent Show. His -th cow has weight and talent , 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 (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 , 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 and the weight threshold .
Lines through each contain two integers. The integers on line give the weight and talent of the -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 .
If your answer is , output the value of 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 , your program may produce due to floating-point precision and, after flooring, incorrectly output . In this case, you can add a tiny value before flooring, e.g., , 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 and weight . However, since we need at least units of weight, the optimal solution is to use that cow together with the cow of talent and weight . The resulting ratio is , which becomes after multiplying by and taking the floor.
Constraints
For all testdata, it is guaranteed that , , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号