Hill Drive
Time limit1sMemory limit128 MB
Given fuel and a per-road speed-dependent consumption model with a speed cap, choose speeds per road segment to minimize total travel time under a total fuel budget.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Math
- Solved
- No attempts yet
Problem
Sanggeun has driven up a nearby mountain and now wants to get back home as quickly as possible. His car is low on fuel, so he has to drive as efficiently as he can.
Part of the way home is uphill and part is downhill. Every road segment has its own length and slope. Given how much fuel is left in the car, determine the shortest possible time to get home.
The car's fuel usage is modeled simply. The fuel consumption (liters per km) grows in proportion to the speed and is offset by the slope of the road:
Here is the flat-ground consumption factor, is the speed in km/h, is the slope of the road, and is a positive constant. For intuition, suppose a hill can be descended at km/h while burning no fuel; driving up that same hill then uses as much fuel as driving km/h faster on flat ground. Accelerating and decelerating use no fuel and happen instantly. The car also has a top speed that it can never exceed.
Distances are given in meters. For a road segment with horizontal length and height change , the actual distance driven is meters and its slope is . Speeds are in km/h and the travel time is measured in hours.
Input
The first line contains the number of test cases (). Each test case is given as follows.
The first line of a test case contains four real numbers (), (), (), and (), where is the car's top speed in km/h and is the fuel left in liters.
The next line contains the number of roads ().
Each of the next lines contains two real numbers and (, ): the horizontal length and the height change of the -th road, both in meters. Each road has a constant slope.
Output
For each test case, print on its own line the minimum time in hours needed to get home, rounded to exactly 6 digits after the decimal point (for example, printf("%.6f")). If it is impossible to get home with the available fuel, print IMPOSSIBLE instead. When getting home is possible, the required time is always less than 24 hours. The test data is chosen so that the exact answer is never close to a rounding boundary.