#P8237. [AGM 2022 资格赛] 过河
[AGM 2022 资格赛] 过河
Problem Description
A person comes to cross a river.
The river can be viewed as a shape on a 2D coordinate system. The left bank where the person starts is the -axis, and the right bank is the line .
There are horizontal logs on the river. The -th log has -coordinate , and it covers points whose -coordinate ranges from to .
The person can jump back and forth between logs and the banks. The -th log can jump to the -th log if and only if and there exists a real number such that , and there does not exist a log such that and . Similarly, if a log wants to jump to a bank, treat the -range covered by the bank as , and the same condition must be satisfied.
The cost to jump from the -th log to anywhere else is . Jumping from a bank to anywhere else costs nothing. The left bank cannot jump directly to the right bank.
The person wants to know the minimum total cost to reach the right bank.
Input Format
The first line contains a positive integer .
The next lines each contain four integers .
Output Format
Output one number representing the answer. It is guaranteed that there exists a way to reach the right bank.
8
1 1 4 10
4 2 5 10
2 3 5 1
3 2 4 1
2 1 3 1
5 1 3 1
6 1 2 10
6 2 3 10
4
Hint
Constraints
For of the testdata, , , .
The testdata guarantees that logs do not overlap: there do not exist such that and .
Notes
Translated from AGM 2022 Qualification Round I River。
Translated by ChatGPT 5