Formula Race
Time limit1sMemory limit128 MB
Finish exactly N laps with refueling pit stops and two tire types, both used at least once, in minimum total time.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Shortest path
- Solved
- No attempts yet
Problem
In a popular motorsport, a race car must complete exactly full laps of the track. Every lap burns a fixed amount of fuel, so we measure fuel by the number of laps it still allows. Having units of fuel in the tank means the car can drive more laps without refueling, and each completed lap lowers the fuel by . The tank can hold at most units.
After finishing a lap, the car may (but need not) enter the pit lane for seconds. During a pit stop the crew may perform any of the following:
- Add fuel to the tank (never above )
- Change the type of tire the car runs on
The team has two types of tires. A lap's duration depends on:
- The amount of fuel currently in the tank
- The type of tire fitted
Given the lap time as a function of fuel level and tire type, find the minimum time to finish the whole race, subject to one rule:
- Each tire type must be used for at least one lap
The team is free to choose the starting fuel level and the starting tire type at the moment the race begins.
Input
The first line contains an integer , the number of test cases. The race descriptions follow, separated by blank lines.
Each race begins with a line containing two numbers and (, ).
The next lines describe the car's performance. Line (numbered from ) contains two numbers and . Here is the time to drive one lap that starts with exactly units of fuel using tires of the first type, and is the same value for the second type of tires (). After such a lap the fuel drops to .
is an integer. , , and are real numbers given with exactly three digits after the decimal point.
The car obeys physics: less fuel never makes it slower. Formally, and for every where both sides are defined.
Output
For each race, print on its own line the minimum time to finish that race, with exactly three digits after the decimal point.