Under construction

Still being built. Things may change

Speed Ups

Interview

Time limit2sMemory limit1024 MB

Summary
Given speed-up boosts at fixed meter marks, find the fastest finishing time when a taken boost blocks any other boost until it ends.
Level

Medium5 of 10

Topics
Dynamic programming, Sorting
Solved
No attempts yet

Problem

In a video game called Speed Ups, you are a single player running a race. The goal is to finish the race as fast as possible. Your regular speed is 1 meter/second. At different meter markers, you may get the choice of a speed up. Each speed up is an ordered triplet of integers (x,m,d)(x, m, d). You can use it exactly xx meters after the start of the race, which gives you a temporary speed of mm meters per second for dd seconds. While you are using a speed up, you cannot use another one. So if you take one speed up, you may run past the location of another speed up that would have been better.

For example, suppose a 100 meter race has two speed ups: (10,2,5)(10, 2, 5) and (15,3,20)(15, 3, 20). You run the first 10 meters in 10 seconds. If you take the first speed up, you run 5 seconds at 2 meters per second and reach the 20 meter mark at 15 seconds. That is past the second speed up at 15 meters, so you cannot take it. You then finish in 10+5+80=9510 + 5 + 80 = 95 seconds. If you skip the first speed up and take the second one at 15 meters, you run 20 seconds at 3 meters per second, reach the 75 meter mark at 35 seconds, and finish in 60 seconds. That is the fastest finish for this example.

Input

The first line has two integers: nn (1≤n≤10001 \le n \le 1000), the number of speed ups, and LL (1≤L≤1091 \le L \le 10^{9}), the length of the race in meters.

Each of the next nn lines has three integers xx (1≤x≤L−11 \le x \le L - 1), mm (2≤m≤1002 \le m \le 100), and dd (1≤d≤1061 \le d \le 10^{6}). This describes a speed up at xx meters from the start that sets your speed to mm meters per second for dd seconds.

Notes:

  • Several speed ups can be at the same location, but you can take only one of them.
  • Once you take a speed up, you must use it until it completes or the race ends, whichever comes first.
  • You cannot use another speed up until the current one is fully completed.
  • If a speed up puts you at distance yy from the start and a new speed up is exactly at yy, you can take the new one.

Output

Print the fastest possible finishing time in seconds on a single line. An answer is accepted if its absolute or relative error is within 10−610^{-6}.

Hint

In the second sample, taking the first speed up is better than taking the third one, because the third one prevents you from taking the second. Taking the first speed up at 25 meters gives 25 seconds at 3 meters per second, so you reach the 100 meter mark at 50 seconds. Then you take the second speed up and run 400 seconds at 2 meters per second, reaching the 900 meter mark at 450 seconds. The last 100 meters take 100 seconds at 1 meter per second.

In the last sample, the speed up taken at 7 seconds lasts 200 seconds, but the race ends first. You run the remaining 43 meters at 4 meters per second in 10.75 seconds.

Examples3

  1. Example 1

    Input
    2 100
    10 2 5
    15 3 20
    
    Expected output
    60.0
    
  2. Example 2

    Input
    3 1000
    25 3 25
    100 2 400
    25 5 20
    
    Expected output
    550.0
    
  3. Example 3

    Input
    1 50
    7 4 200
    
    Expected output
    17.75