#P15290. [MCO 2023] Two Pointers (easy version)

    ID: 15306 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>贪心2023枚举MCC/MCO(马来西亚)

[MCO 2023] Two Pointers (easy version)

Description

Alice and Bob are visiting cities on a very long road that stretches from points 109-10^9 to 10910^9. Alice starts at point AA while Bob starts at point BB.

There are nn cities to visit, where the ii-th city is at point tit_i. Each city must be visited by Alice or Bob at least once, but they can be visited in any order\textbf{any order}.

What is the minimum total\textbf{total} distance Alice and Bob travel?

Input Format

Each test consists of multiple test cases. The first line contains a single integer TT (1T1001 \le T \le 100), the number of test cases. Each test case is formatted as follows:

The first line contains three space-separated integers nn, AA, and BB (1n21051 \le n \le 2 \cdot 10^5, 109A,B109-10^9 \le A, B \le 10^9) -- the number of cities, Alice's position, and Bob's position, respectively.

The second line contains nn space-separated integers t1,t2,,tnt_1, t_2, \ldots, t_n (109ti109-10^9 \le t_i \le 10^9) -- the positions of the cities.

It is guaranteed that the sum of nn over all test cases is at most 21052 \cdot 10^5.

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 77 cities. Alice starts at coordinate 6-6 and Bob starts at point 1010.

One possible optimal way to visit all cities is as follows (ixji \xrightarrow{x} j means to go from ii to jj, driving xx 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 0+9=90 + 9 = 9 distance and Bob drives for a total of 1+1+4+8+1=151 + 1 + 4 + 8 + 1 = 15 distance. The total distance driven by both Alice and Bob is 9+15=249 + 15 = 24. It can be proven that there is no way to drive less than 2424 distance, thus the answer is 2424.

In the second test case, Alice and Bob are both already at city 22. Bob can visit the city 22 then city 11, driving 2,000,000,0002,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 44 to point 11 for 33 distance. Bob does nothing.

Scoring

Subtask 1 (1616 points): n20n \le 20, 106A,B,ti106-10^6 \le A, B, t_i \le 10^6

Subtask 2 (3636 points): n5000n \le 5000, 106A,B,ti106-10^6 \le A, B, t_i \le 10^6

Subtask 3 (2121 points): n5000n \le 5000

Subtask 4 (2727 points): No additional constraints