Just Buy Your Drinks, Please
Time limit3sMemory limit1024 MB
Each query asks for the highest taste threshold t such that liquids with d_i >= t can supply at least L liters within budget g, respecting per-liquid caps.
- Level
Hard8 of 10
- Topics
- Binary search, Sorting, Greedy, Prefix sum
- Solved
- No attempts yet
Problem
Jaehyun has taken up a hobby of mixing various liquids to make drinks.
The mart sells liquids numbered . Liquid has a taste of and costs per liter. A single bottle of the drink Jaehyun makes may use at most liters of liquid . (Breaking this rule may put your health in serious danger.)
A bizarre rumor spread that drinking Jaehyun's beverage lets you trade health for problem-solving skill, so people came to Jaehyun's house to drink one bottle each. Person wants the liquid used to make one bottle to cost at most and the volume to be at least liters. Under these conditions, person wants to maximize the taste of the drink. Here, the taste of a drink is the minimum among the tastes of the liquids that make it up.
For each person, output the taste of the drink that person will drink. If you cannot serve a drink, output -1.
Input
The first line contains two integers ().
Then lines follow, each with three integers . ()
Then lines follow, each with two integers . ()
Output
Output the answers in lines. On line , output the taste of the drink person will drink. If you cannot serve a drink, output -1.