#P10726. [GESP202406 八级] 空间跳跃
[GESP202406 八级] 空间跳跃
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1156.
Problem Description
Xiao Yang has horizontal platforms in a 2D space, and the platforms do not overlap with each other. The -th platform is at height , and its left and right endpoints are at and , respectively.
Xiao Yang can move left and right on a platform. When Xiao Yang reaches the right endpoint, if he moves further right, he will fall vertically and land on the first platform below. The same applies to the left endpoint. Each time Xiao Yang moves unit of horizontal distance on a platform, it costs unit of time. While falling, each unit of height also costs unit of time.
Xiao Yang wants to know the minimum time needed to start from the left endpoint of the -th platform and reach the -th platform.
Note: It may be impossible to reach the -th platform from the -th platform.
Input Format
The first line contains a positive integer , representing the number of platforms.
The second line contains two positive integers , as described in the statement.
The next lines each contain three positive integers , representing the left endpoint, right endpoint, and height of the -th platform.
Output Format
Output one integer representing the minimum time required. If it is impossible to reach, output .
3
3 1
5 6 3
3 5 6
1 4 100000
100001
Hint
Sample Explanation
The minimum-time movement plan is: move from the left endpoint of platform to its right endpoint, costing units of time; then move right and fall onto platform , costing units of time; then move right by unit of distance, costing unit of time; finally move right and fall onto platform , costing units of time. The total cost is units of time.
Constraints
| Subtask ID | Percentage | Special condition | |
|---|---|---|---|
For all testdata, it is guaranteed that , , and .
Translated by ChatGPT 5