#P5638. 【CSGRound2】光骓者的荣耀
【CSGRound2】光骓者的荣耀
Description
The land that Little K has conquered contains a total of cities. City and city are connected by a two-way highway, and traveling along this road takes time .
In order to care about the people’s lives, Little K decides to make regular visits. Each time, he will travel from city to city and visit the cities he passes through. The destination must be city .
Moreover, he has a teleporter with teleport radius , meaning he can teleport to and . If the target city index is less than , it becomes ; if it is greater than , it becomes .
However, his teleporter does not have enough power and can only be used once. Also, for some reason, he wants to finish the visits as quickly as possible, so he asks you, the Minister of Transportation, what the minimum time is.
Note: He does not need to visit all cities, and using the teleporter costs no time.
Input Format
Two lines. The first line contains two positive integers .
The second line contains integers, where the -th one denotes .
Output Format
One integer, indicating the answer.
4 0
1 2 3
6
4 1
1 2 3
3
Hint
Sample Explanation 1:
The illustrations for samples 1 and 2 are both the following image:

If the teleporter is not used and you just walk directly, the answer is . It can be proven that this is the minimum.
Sample Explanation 2:
Use it at and teleport to . The answer is . It can be proven that this is the minimum.
Constraints:
For all testdata, , , .
| Test Point ID | Range of | Range of | Range of |
|---|---|---|---|
Translated by ChatGPT 5
京公网安备 11011102002149号