Water Tank
Time limit8sMemory limit512 MB
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 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 . The rate is a nonnegative real number.
- Water beyond the capacity spills out, so the stored volume is always at most .
- The tank is full at time 0 of the first day.
Let be the stored volume at time . The requirement is 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 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 and (, ). is the number of schedules in the table and is the capacity of the tank.
The -th of the following lines describes the -th schedule with three integers , and . The first two are the starting time and the ending time of the schedule, and is the volume consumed per unit of time during the schedule (). The times satisfy .
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 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 . No answer lies within of a rounding boundary of the sixth decimal digit, so the value to print is uniquely determined.