Kiddie Pool
Time limit5sMemory limit512 MB
Choose when to run each hot or cold source so the pool holds exactly V liters at temperature X in the shortest time.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Sorting
- Solved
- No attempts yet
Problem
A kiddie pool is a big container that you fill with water so that small children can play in it.
You have different water sources. Source produces water at a rate of liters per second, and that water has temperature . Every source starts switched off. Each source can be switched on only once and switched off only once, and switching a source on or off takes no time. Several sources can be on at the same time.
The pool holds any amount of water, but you want to fill it with exactly volume at exactly temperature , as quickly as possible. If you switch the sources on and off optimally, what is the minimum number of seconds this takes? You do not have to use every source.
In this problem, combining water of volume and temperature with water of volume and temperature instantly produces water of volume and temperature . For example, combining 5 liters of water at 10 degrees with 10 liters of water at 40 degrees gives 15 liters of water at 30 degrees. Water never heats up or cools down over time except by being combined with other water.
Input
The first line contains the number of test cases . test cases follow.
The first line of each test case contains an integer and real numbers and , separated by spaces. Each of the next lines contains the flow rate and the temperature of source , separated by a space. Volume is measured in liters, flow rate in liters per second, and temperature in degrees Celsius.
Every real number is given with exactly four digits after the decimal point.
Limits
- Whenever an answer exists, it is smaller than .
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the minimum number of seconds needed to fill the pool to the target volume and target temperature. If the input makes that impossible, print IMPOSSIBLE in place of .
Round at the seventh digit after the decimal point and print exactly six digits after the decimal point, including trailing zeros. In every test case the answer is far enough from a rounding boundary that double precision arithmetic gives the same printed value.
Hint
In the first sample test case the only source already has the target temperature. Turning it on immediately and leaving it running until the pool holds 10 liters is optimal, and at 0.2 liters per second that takes 50 seconds.
In the second sample test case one optimal plan runs the first source for about 207221.843687 seconds and also turns on the second source about 0.092778 seconds before the end.
In the third sample test case both sources are colder than the target temperature, so the target temperature is out of reach.