This page is still under construction.

Parts of this page are still being built. What you see may change.

Formula Race

Time limit1sMemory limit128 MB

Summary
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 NN 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 ii units of fuel in the tank means the car can drive ii more laps without refueling, and each completed lap lowers the fuel by 11. The tank can hold at most NN units.

After finishing a lap, the car may (but need not) enter the pit lane for PP seconds. During a pit stop the crew may perform any of the following:

  • Add fuel to the tank (never above NN)
  • 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 TT, the number of test cases. The race descriptions follow, separated by blank lines.

Each race begins with a line containing two numbers NN and PP (1<N≤10001 < N \le 1000, 0<P≤1000 < P \le 100).

The next NN lines describe the car's performance. Line ii (numbered from 11) contains two numbers XiX_i and YiY_i. Here XiX_i is the time to drive one lap that starts with exactly ii units of fuel using tires of the first type, and YiY_i is the same value for the second type of tires (0<Xi,Yi≤10000 < X_i, Y_i \le 1000). After such a lap the fuel drops to i−1i-1.

NN is an integer. PP, XiX_i, and YiY_i are real numbers given with exactly three digits after the decimal point.

The car obeys physics: less fuel never makes it slower. Formally, Xi≤Xi+1X_i \le X_{i+1} and Yi≤Yi+1Y_i \le Y_{i+1} for every ii 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.

Examples1

  1. Example 1

    Input
    2
    3 5.000
    1.000 7.000
    2.000 9.000
    3.000 11.000 
    
    5 15.000 
    1.000 5.000
    45.000 10.000
    80.000 99.342 
    122.000 1000.000
    1000.000 1000.000
    
    Expected output
    15.000
    61.000