#t85. 最短旅行时间
最短旅行时间
Minimum Travel Time
Problem Description
There are cities, numbered . Between city and city there is a bidirectional road, and traversing it takes time .
You start from city and want to reach city . Apart from the roads, you also have a teleporter with a range of : once used, it takes you directly from city to city or city ; if the target index is less than it is treated as , and if greater than it is treated as . The teleporter can be used at most once, and using it consumes no time.
You do not need to visit every city. Find the minimum time needed to travel from city to city .
Input Format
Two lines. The first line contains two positive integers (, ).
The second line contains integers; the -th number is ().
Output Format
Output a single integer: the minimum travel time.
Sample Input 1
4 0
1 2 3
Sample Output 1
6
Sample Input 2
4 1
1 2 3
Sample Output 2
3