Kiddie Pool

Time limit5sMemory limit512 MB

Summary
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 NN different water sources. Source ii produces water at a rate of RiR_i liters per second, and that water has temperature CiC_i. 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 VV at exactly temperature XX, 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 V0V_0 and temperature X0X_0 with water of volume V1V_1 and temperature X1X_1 instantly produces water of volume V0+V1V_0 + V_1 and temperature (V0X0+V1X1)/(V0+V1)(V_0 X_0 + V_1 X_1) / (V_0 + V_1). 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 TT. TT test cases follow.

The first line of each test case contains an integer NN and real numbers VV and XX, separated by spaces. Each of the next NN lines contains the flow rate RiR_i and the temperature CiC_i of source ii, 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

  • 1≤T≤1001 \le T \le 100
  • 1≤N≤1001 \le N \le 100
  • 0.0001≤V≤10000.00.0001 \le V \le 10000.0
  • 0.1≤X≤99.90.1 \le X \le 99.9
  • 0.0001≤Ri≤10000.00.0001 \le R_i \le 10000.0
  • 0.1≤Ci≤99.90.1 \le C_i \le 99.9
  • Whenever an answer exists, it is smaller than 10610^6.

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy 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 yy.

Round yy 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.

Examples1

  1. Example 1

    Input
    6
    1 10.0000 50.0000
    0.2000 50.0000
    2 30.0000 65.4321
    0.0001 50.0000
    100.0000 99.9000
    2 5.0000 99.9000
    30.0000 99.8999
    20.0000 99.7000
    2 0.0001 77.2831
    0.0001 97.3911
    0.0001 57.1751
    2 100.0000 75.6127
    70.0263 75.6127
    27.0364 27.7990
    4 5000.0000 75.0000
    10.0000 30.0000
    20.0000 50.0000
    300.0000 95.0000
    40.0000 2.0000
    
    Expected output
    Case #1: 50.000000
    Case #2: 207221.843687
    Case #3: IMPOSSIBLE
    Case #4: 0.500000
    Case #5: 1.428035
    Case #6: 18.975332