Talent Show
Time limit2sMemory limit512 MB
Choose a group of cows with total weight at least W maximizing the ratio of total talent to total weight, and print floor(1000A).
- Level
Medium6 of 10
- Topics
- Dynamic programming, Binary search, Greedy
- Solved
- No attempts yet
Problem
Farmer John brings his cows, numbered through , to the county fair for the annual bovine talent show. Cow has weight and talent level , both integers.
The rules of this year's show are new.
(i) The group of cows entered into the show must have total weight at least . The rule exists so that one outstanding cow cannot win on its own.
(ii) The group with the largest ratio of total talent to total weight wins.
All of Farmer John's cows together weigh at least , so a group satisfying rule (i) always exists. Determine the largest ratio of total talent to total weight he can reach with such a group.
Input
The first line contains () and (). Each of the next lines describes one cow with two integers () and ().
Output
Let be the largest ratio of total talent to total weight reachable by a group whose total weight is at least . Print the floor of , which keeps the output integer. The floor operation discards the fractional part and rounds down to an integer, and leaves a value that is already an integer unchanged.
Hint
In the first example the best ratio for a single cow belongs to the cow with talent 11 and weight 10. The group needs total weight at least 15, so the best group adds the cow with talent 21 and weight 20. That group has ratio , and multiplying by 1000 and taking the floor gives 1066.