#P15290. [MCO 2023] Two Pointers (easy version)
[MCO 2023] Two Pointers (easy version)
Description
Alice and Bob are visiting cities on a very long road that stretches from points to . Alice starts at point while Bob starts at point .
There are cities to visit, where the -th city is at point . Each city must be visited by Alice or Bob at least once, but they can be visited in .
What is the minimum distance Alice and Bob travel?
Input Format
Each test consists of multiple test cases. The first line contains a single integer (), the number of test cases. Each test case is formatted as follows:
The first line contains three space-separated integers , , and (, ) -- the number of cities, Alice's position, and Bob's position, respectively.
The second line contains space-separated integers () -- the positions of the cities.
It is guaranteed that the sum of over all test cases is at most .
Output Format
For each test case, print the answer on a separate line.
Output the minimum total distance that Alice and Bob must travel to visit all cities.
4
7 -6 10
-15 -1 12 8 11 -6 0
2 -1000000000 -1000000000
1000000000 -1000000000
1 4 6
1
4 727 137
39 852 201 696
24
2000000000
3
413
Hint
Note
:::align{center}
:::
In the first test case: There are cities. Alice starts at coordinate and Bob starts at point .
One possible optimal way to visit all cities is as follows ( means to go from to , driving distance):
- Alice visits the cities (given in order): $A \xrightarrow{0} \text{city }6 \xrightarrow{9} \text{city }1$.
- Bob visits the cities (given in order): $B \xrightarrow{1} \text{city }5 \xrightarrow{1} \text{city }3 \xrightarrow{4} \text{city }4 \xrightarrow{8} \text{city }7 \xrightarrow{1} \text{city }2$.
Alice drives for a total of distance and Bob drives for a total of distance. The total distance driven by both Alice and Bob is . It can be proven that there is no way to drive less than distance, thus the answer is .
In the second test case, Alice and Bob are both already at city . Bob can visit the city then city , driving total distance. Note that Alice can choose to do nothing.
In the third test case, Alice can visit the only city, driving from point to point for distance. Bob does nothing.
Scoring
Subtask 1 ( points): ,
Subtask 2 ( points): ,
Subtask 3 ( points):
Subtask 4 ( points): No additional constraints
京公网安备 11011102002149号