| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 74 | 37 | 34 | 50.746% |
Alice and Bob are visiting cities on a very long road that stretches from points $-10^9$ to 10ドル^9$. Alice starts at point $A$ while Bob starts at point $B$.
There are $n$ cities to visit, where the $i$-th city is at point $t_i$. Each city must be visited by Alice or Bob at least once, but they can be visited in any order.
What is the minimum total distance Alice and Bob travel?
Each test consists of multiple test cases. The first line contains a single integer $T$ (1ドル \le T \le 100$), the number of test cases. Each test case is formatted as follows:
The first line contains three space-separated integers $n,ドル $A,ドル and $B$ (1ドル \le n \le 2 \cdot 10^5,ドル $-10^9 \le A, B \le 10^9$) -- the number of cities, Alice's position, and Bob's position, respectively.
The second line contains $n$ space-separated integers $t_1, t_2, \ldots, t_n$ ($-10^9 \le t_i \le 10^9$) -- the positions of the cities.
It is guaranteed that the sum of $n$ over all test cases is at most 2ドル \cdot 10^5$.
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.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 16 | $n \le 20,ドル $-10^6 \le A, B, t_i \le 10^6$ |
| 2 | 36 | $n \le 5000,ドル $-10^6 \le A, B, t_i \le 10^6$ |
| 3 | 21 | $n \le 5000$ |
| 4 | 27 | No additional constraints |
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
In the first test case: There are 7ドル$ cities. Alice starts at coordinate $-6$ and Bob starts at point 10ドル$.
One possible optimal way to visit all cities is as follows ($i \xrightarrow{x} j$ means to go from $i$ to $j,ドル driving $x$ distance):
Alice drives for a total of 0ドル + 9 = 9$ distance and Bob drives for a total of 1ドル + 1 +たす 4 +たす 8 +たす 1 =わ 15$ distance. The total distance driven by both Alice and Bob is 9ドル + 15 = 24$. It can be proven that there is no way to drive less than 24ドル$ distance, thus the answer is 24ドル$.
In the second test case, Alice and Bob are both already at city 2ドル$. Bob can visit the city 2ドル$ then city 1ドル,ドル driving 2,000,000,000ドル$ total distance. Note that Alice can choose to do nothing.
In the third test case, Alice can visit the only city, driving from point 4ドル$ to point 1ドル$ for 3ドル$ distance. Bob does nothing.