#P15944. [JOI Final 2026] 传送机 2 / Teleporter 2
[JOI Final 2026] 传送机 2 / Teleporter 2
Problem Description
There are points on a straight path, numbered from left to right. The path is one-way from left to right.
There are also teleporter devices numbered . By using device (), one can warp from point to point ().
Bitaro is currently at point and wants to reach point . When Bitaro is at point (), he can take one of the following actions:
- Move on foot to point .
- Choose an () satisfying , use device , and warp to point .
It is known that warp travel places stress on the body. You are concerned about Bitaro’s safety, so you decide to destroy zero or more teleporter devices so that, no matter which route Bitaro takes, the number of warp travels is at most . Device can be destroyed by paying cost ; if so, Bitaro can no longer use that device.
Find the minimum possible total cost you need to pay when destroying zero or more teleporter devices so that, regardless of Bitaro’s route, the number of warp travels is at most .
Input Format
Read the following data from the standard input.
Output Format
Write one line to the standard output containing the minimum possible total cost.
8 4 1
1 4 3
2 3 5
3 6 2
5 8 2
4
12 7 2
1 5 3
4 8 2
2 4 5
2 4 8
7 9 4
9 11 7
3 10 5
6
6 3 2
1 4 2
2 5 4
3 6 3
0
Hint
Sample 1
Consider the case where devices and are destroyed.
Then Bitaro can use only devices and . When moving from point to point , Bitaro will always make at most one warp travel, so the condition is satisfied.
In this case, the total paid cost is . Since it is impossible to make the cost at most , the correct output is .
This input example satisfies the constraints of all subtasks.
Sample 2
Destroying devices and is optimal.
This input example satisfies the constraints of subtasks .
Sample 3
In this case, there is no need to destroy any device.
This input example satisfies the constraints of subtasks .
Constraints
- .
- .
- ().
- ().
- Given values are all integers.
Subtasks
- (5 points) .
- (3 points) , .
- (29 points) , .
- (23 points) , .
- (24 points) , .
- (16 points) No additional constraints.