Logo
(追記) (追記ここまで)

29819번 - Two Pointers (easy version) 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB74373450.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.

제한

서브태스크

번호배점제한
116

$n \le 20,ドル $-10^6 \le A, B, t_i \le 10^6$

236

$n \le 5000,ドル $-10^6 \le A, B, t_i \le 10^6$

321

$n \le 5000$

427

No additional constraints

예제 입력 1

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

예제 출력 1

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 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 = 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.

출처

Olympiad > Malaysian Computing Olympiad > MCO 2023 A번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /