Race
Time limit1sMemory limit512 MB
Find the length-m segment of the road that minimizes total riding time under piecewise constant speed limits.
- Level
Medium6 of 10
- Topics
- Sliding window, Prefix sum, Two pointers
- Solved
- No attempts yet
Problem
The Tour de Bajtocja race is held every year on a road that runs from city A to city B. This year, because of a budget shortfall, the race will take place on only one segment of the road. Which segment it will be has not been decided yet, but the length of that segment is already fixed.
Speed-limit signs are placed along the road. The limit set by a sign stays in force until the next sign sets a new limit. In this race the speed limits must always be obeyed, so when the limit at some place is , crossing a stretch of length there takes time .
The organizers are wondering where to place the segment of length so that, while obeying the speed limits, it can be ridden as fast as possible. Write a program that finds the shortest time needed to ride such a segment.
Input
The first line contains three integers , , and separated by single spaces (, ): the number of signs on the road, the length of the segment on which the race will be held, and the total length of the road from A to B, respectively.
Each of the next lines describes one sign with two integers and (, ): the distance of the -th sign from city A and the speed limit that applies starting at that sign. It is guaranteed that .
Output
Print, on a single line, the shortest time needed to ride a segment of length , rounded to exactly three digits after the decimal point. The chosen segment must lie entirely within the road from A to B (it may not start before A or end beyond B).
Hint

Explanation: For the sample input, the best segment starts at distance from city A. The time to ride it is .
Tip: To avoid rounding errors, use a double-precision floating-point type (double) and the standard routines for printing real numbers with a given precision.