#P1442. 铁球落地
铁球落地
Description
In a 2D coordinate system, there are platforms (a platform is defined as a horizontal open line segment whose two endpoints share the same -coordinate; an open line segment means its two endpoints are not part of the segment itself) and one iron ball. If there is no object directly below, the ball falls unit length per second.
Each time the ball lands on a platform, the player may choose to roll horizontally to the left or to the right. The rolling speed is unit length per second. Because the iron ball is fragile, the height of each single drop must not exceed .
Design a strategy to make the ball reach the ground as quickly as possible without breaking.
Assume the ground has height and is infinitely wide. The ball’s size is negligible compared to the platforms and can be treated as a point mass. Please note: the ball begins to fall as soon as it reaches an endpoint of a platform; it does not need to roll into the next cell. For example, in the figure below, the ball at has already started to fall.

Input Format
The first line contains two integers representing the number of platforms and the maximum allowed drop height .
The second line contains two integers , indicating that the iron ball starts at position .
Lines to : each line contains three integers. On line , the integers denote the -coordinate of the -th platform and the -coordinates of its left and right endpoints, respectively.
Output Format
Output one line with a single integer: the minimum total time to reach the ground.
5 3
6 10
5 2 4
9 3 9
6 7 10
2 1 5
3 8 11
15
10 156
84 139
63 22 50
79 96 100
87 77 98
60 24 53
47 1 29
62 55 89
68 68 78
10 5 85
85 67 71
73 57 61
155
Hint
Constraints and Conventions
For all test points, it is guaranteed that:
- .
- , .
- All are pairwise distinct; all and are also pairwise distinct; and for any , it holds that .
- The testdata guarantees there is a solution, and the final answer does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号