K Best
Time limit2sMemory limit64 MB
Choose exactly k jewels out of n to maximize the ratio of total value to total weight, using binary search on the answer with a fractional feasibility check, then output the exact reduced fraction.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Math
- Solved
- No attempts yet
Problem
Demy has jewels. The -th jewel has value and weight .
She wants to keep exactly of them so that their specific value is as large as possible. For a chosen set the specific value is defined as
Determine the maximum possible specific value over all subsets of size .
Input
The first line contains two integers and — the number of jewels and the number to keep ().
Each of the next lines contains two integers and (, ). Both and are at most .
Output
The maximum specific value is a rational number. Output it as an irreducible fraction p/q, where and are integers with . Always print the denominator (for example 3/1). If the value is , print 0/1.