Water Tank

Time limit8sMemory limit512 MB

Summary
Given a daily repeating schedule of water usage, find the minimum constant pump rate that keeps the tank from ever running dry.
Level

Hard8 of 10

Topics
Binary search, Simulation, Prefix sum, Greedy
Solved
No attempts yet

Problem

You built an apartment and installed a water tank of capacity LL that stores water for the residents. The tank works as a buffer between the water company and the residents.

The residents must not run short of water while they use it. A pump fills the tank. A stronger pump makes a shortage less likely, but a stronger pump costs more, so you want the weakest pump that still meets the requirement.

The daily schedule table of water usage is the same every day. The table is made of several schedules, and each schedule is given by the starting time of the usage, the ending time, and the volume used per unit of time during that span.

Write a program that reads a schedule table and computes the minimum required speed of providing water.

The following conditions hold.

  • A day consists of 86400 units of time.
  • No schedule starts before time 0, and no schedule ends after time 86400.
  • No two schedules overlap.
  • Water is not consumed outside the schedules.
  • The pump runs all day without stopping and adds water at a constant rate rr. The rate rr is a nonnegative real number.
  • Water beyond the capacity LL spills out, so the stored volume is always at most LL.
  • The tank is full at time 0 of the first day.

Let V(t)V(t) be the stored volume at time tt. The requirement is V(t)≥0V(t) \ge 0 at every moment. The schedule table repeats in the same form every day without end, and the requirement must hold on every day. Find the smallest rr that satisfies it.

Input

The input is a sequence of datasets. Each dataset corresponds to one schedule table in the following format.

N L
s1 t1 u1
...
sN tN uN

The first line of a dataset contains two integers NN and LL (1≤N≤864001 \le N \le 86400, 1≤L≤1061 \le L \le 10^6). NN is the number of schedules in the table and LL is the capacity of the tank.

The ii-th of the following NN lines describes the ii-th schedule with three integers sis_i, tit_i and uiu_i. The first two are the starting time and the ending time of the schedule, and uiu_i is the volume consumed per unit of time during the schedule (1≤ui≤1061 \le u_i \le 10^6). The times satisfy 0≤s1<t1≤s2<t2≤⋯≤sN<tN≤864000 \le s_1 < t_1 \le s_2 < t_2 \le \cdots \le s_N < t_N \le 86400.

The input ends with a line that holds two zeros. Do not process that line.

One input holds at most 20 datasets, and the sum of NN over all datasets is at most 100000.

Output

For each dataset, print on its own line the minimum amount of water per unit of time that the pump must provide, rounded to exactly six digits after the decimal point.

The answer is always at most 10610^6. No answer lies within 10−910^{-9} of a rounding boundary of the sixth decimal digit, so the value to print is uniquely determined.

Examples1

  1. Example 1

    Input
    1 100
    0 86400 1
    1 100
    43200 86400 1
    0 0
    
    Expected output
    1.000000
    0.997685