#P10726. [GESP202406 八级] 空间跳跃

[GESP202406 八级] 空间跳跃

Background

Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1156.

Problem Description

Xiao Yang has nn horizontal platforms in a 2D space, and the platforms do not overlap with each other. The ii-th platform is at height hih_i, and its left and right endpoints are at lil_i and rir_i, 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 11 unit of horizontal distance on a platform, it costs 11 unit of time. While falling, each 11 unit of height also costs 11 unit of time.

Xiao Yang wants to know the minimum time needed to start from the left endpoint of the ss-th platform and reach the tt-th platform.

Note: It may be impossible to reach the tt-th platform from the ss-th platform.

Input Format

The first line contains a positive integer nn, representing the number of platforms.

The second line contains two positive integers s,ts, t, as described in the statement.

The next nn lines each contain three positive integers li,ri,hil_i, r_i, h_i, representing the left endpoint, right endpoint, and height of the ii-th platform.

Output Format

Output one integer representing the minimum time required. If it is impossible to reach, output 1-1.

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 33 to its right endpoint, costing 33 units of time; then move right and fall onto platform 22, costing 1000006=99994100000 - 6 = 99994 units of time; then move right by 11 unit of distance, costing 11 unit of time; finally move right and fall onto platform 11, costing 33 units of time. The total cost is 100001100001 units of time.

Constraints

Subtask ID Percentage nn Special condition
11 20%20\% 1000\leq 1000 li=1l_i = 1
22 40%40\% li=i,ri=i+1l_i = i, r_i = i + 1
33

For all testdata, it is guaranteed that 1n10001 \leq n \leq 1000, 1liri1051 \leq l_i \leq r_i \leq 10^5, and 1hi1051 \leq h_i \leq 10^5.

Translated by ChatGPT 5