Kiddie Pool
Time limit5sMemory limit512 MB
Choose on-off times for sources with different flow rates and temperatures to collect exactly V liters at temperature X in the least time.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Math
- Solved
- No attempts yet
Problem
A kiddie pool is a big container 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 at a temperature of degrees. All sources start off. Each source can be switched on only once and switched off only once, and switching 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 to a volume of exactly liters at a temperature of exactly degrees, as quickly as possible. If you turn the sources on and off optimally, what is the minimum number of seconds it takes? You do not have to use every source.
In this problem, combining water of volume and temperature with water of volume and temperature instantaneously produces water of volume and temperature . For example, combining 5 liters at 10 degrees with 10 liters at 40 degrees gives 15 liters at 30 degrees. Assume water neither heats nor cools 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 three space separated numbers , , and . is an integer and and are real numbers. The next lines each contain the flow rate and the temperature of source , separated by a space. Volume is in liters, flow rate is in liters per second, and temperature is in degrees Celsius.
Every real number is given with exactly four decimal places.
Limits
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 at the target temperature. If the given input makes that impossible, print IMPOSSIBLE in place of .
Print with exactly nine digits after the decimal point. Round at the tenth digit, and round up when the value is exactly halfway. An answer of 50 seconds is printed as 50.000000000.
Notes on the samples
In Case #1 of the first sample, the only source is already at the target temperature. The best plan is to switch it on immediately and let it run until the pool holds 10 liters. It delivers 0.2 liters per second, so this takes 50 seconds.
In Case #2, one optimal plan is to run the first source for 207221.843687375 seconds and also switch the second source on about 0.092778156 seconds before the end.
In Case #3, both sources are colder than the target temperature, so the target cannot be reached.