Under construction

Still being built. Things may change

Out of gas

Time limit5sMemory limit512 MB

Summary
You roll down a hill with free brakes and must reach distance D as fast as possible without ever passing a lead car whose positions are given at sample times.
Level

Medium7 of 10

Topics
Greedy, Math, Simulation
Solved
No attempts yet

Problem

Your car is out of gas and you want to get home as quickly as possible. Your home is at the bottom of a hill and your car is at the top of it. The trouble is that another car is right in front of you and you cannot move past it. Your brakes work, and they are very strong.

You start at the top of the hill with speed 0 m/s at time 0 seconds. Gravity pulls your car down the hill with a constant acceleration. At any time you can use the brakes to reduce your speed by any amount, or to reduce your acceleration temporarily by any amount.

Find the shortest time in which you can reach home if you use the brakes in the best possible way.

Input

The first line holds the number of test cases TT. Then TT test cases follow.

The first line of each test case holds three space separated numbers DD, NN and AA. DD is the distance in meters from the top of the hill to your home, given as a real number with exactly 6 decimal places. NN and AA are integers.

The next NN lines hold two space separated real numbers tit_i and xix_i, both with exactly 6 decimal places. tit_i is a time in seconds and xix_i is a position in meters: at time tit_i the other car is xix_i meters down the hill from your starting point.

The last line holds AA space separated real numbers aia_i, accelerations in m/s2\mathrm{m/s^2}, each with exactly 2 decimal places.

The other car travels at a constant speed between time tit_i and time ti+1t_{i+1}. After time tN−1t_{N-1} it never comes back up the hill, so its position stays at least xN−1x_{N-1}.

For example, if t5=10t_5 = 10, x5=20x_5 = 20, t6=20t_6 = 20 and x6=40x_6 = 40, then 10 seconds after the start the other car is 20 meters down the hill, 15 seconds after the start it is 30 meters down the hill, and 20 seconds after the start it is 40 meters down the hill.

Limits

  • 1≤T≤201 \le T \le 20
  • 1.0≤D≤1041.0 \le D \le 10^4
  • 1≤N≤10001 \le N \le 1000
  • 1≤A≤101 \le A \le 10
  • 1.00≤ai≤9.811.00 \le a_i \le 9.81
  • 0.0≤ti≤1050.0 \le t_i \le 10^5
  • 0.0≤xi≤1050.0 \le x_i \le 10^5
  • t0=0t_0 = 0, ti<ti+1t_i < t_{i+1}
  • xi<xi+1x_i < x_{i+1}
  • xN−1≥Dx_{N-1} \ge D

Output

For each test case, print a line of the form Case #c:, where cc is the test case number starting from 1. Then print AA lines. The ii-th of them holds the minimum number of seconds it takes you to reach home when gravity accelerates you at aia_i and you use the brakes in the best possible way.

Round each time at the seventh decimal place and print it with exactly 6 digits after the decimal point. For example, 25 seconds is printed as 25.000000. Print no blank lines.

Notes

Position and acceleration. An object with a constant acceleration of a m/s2a\ \mathrm{m/s^2} and a starting speed of v0 m/sv_0\ \mathrm{m/s} moves a distance of v0t+12at2v_0 t + \frac{1}{2} a t^2 in tt seconds.

Distance on the slope. Every distance and acceleration is measured along the straight line down the hill, not horizontally. If your car accelerates at 2 m/s22\ \mathrm{m/s^2} from a starting speed of 0 m/s0\ \mathrm{m/s} and the other car is stopped at x=1x = 1, it takes exactly 1 second to reach the other car.

The other car. You may never pass the other car, so at no time may your distance down the hill be greater than its distance. The two distances may be equal. Treat both cars as point masses.

The brakes. They reduce your speed by any amount at any time, and your speed never becomes negative.

Examples2

  1. Example 1

    Input
    3
    1000.000000 2 3
    0.000000 20.500000
    25.000000 1000.000000
    1.00 5.00 9.81
    50.000000 2 2
    0.000000 0.000000
    100000.000000 100.000000
    1.00 1.01
    10000.000000 3 1
    0.000000 0.000000
    10000.000000 0.100000
    10000.100000 100000.000000
    1.00
    
    Expected output
    Case #1:
    44.721360
    25.000000
    25.000000
    Case #2:
    50000.000000
    50000.000000
    Case #3:
    10140.974143
    
  2. Example 2

    Input
    2
    10.000000 3 2
    0.000000 0.000000
    5.000000 1.000000
    6.000000 30.000000
    2.00 9.81
    8.000000 2 2
    0.000000 3.000000
    4.000000 9.000000
    1.00 2.50
    
    Expected output
    Case #1:
    7.162278
    5.976319
    Case #2:
    4.000000
    3.333333