Airport Walkways (Small)
Time limit5sMemory limit512 MB
Spend up to t seconds running, choosing walkway and plain sections, to minimize travel time over a corridor of length X.
Problem
You are in an airport, standing at point 0. A corridor of length leads to the gate, and your plane is about to leave. The corridor holds moving walkways, and walkway moves at speed . When you walk or run on one of them, you move at speed (your own speed ). The walkways never change position; they only add to your speed. The walkways do not overlap: at any point of the corridor there is at most one walkway, but one walkway can begin exactly where another one ends.
Your normal walking speed is . You are worried about missing the plane, so you can run: you can move at speed for at most seconds in total. The seconds do not have to be consecutive. You can split them into any number of intervals, and you may leave part of them unused.
If you choose when to walk and when to run so that you arrive as early as possible, how long does the trip to the gate take?
Input
The first line contains the number of test cases . test cases follow.
The first line of each test case contains five integers , , , and , separated by spaces: the length of the corridor in metres, your walking speed in metres per second, your running speed in metres per second, the largest total time in seconds that you may run, and the number of walkways.
Each of the next lines contains three integers , and : the point where the walkway begins, the point where it ends (both in metres from the start), and the speed of the walkway in metres per second. The walkways are given in increasing order of their starting point.
Limits
Output
For each test case, print one line of the form Case #x: y, where is the test case number starting from 1 and is the time in seconds needed to reach point when you walk and run optimally.
Print rounded to six digits after the decimal point, always with exactly six digits. In the test data the exact answer is at least away from a rounding boundary, so double precision arithmetic is enough.
Note
In the first example the best plan is to start running immediately and run for one second.