#P1661. Checkpoints

Checkpoints

Checkpoints

题面翻译

数轴上有 nn 个点,分别编号为 1,2,...,n1, 2, ..., n 。你初始位置在 aa ,要经过其中的 n1n-1 个点,求最小总行走距离。

输入格式

第一行两个正整数 nnaa

第二行 nn 个正整数 x1,x2,...,xnx_1, x_2, ..., x_n,表示各个点的位置。

1n105,106a,xi1061 \leq n \leq 10^5, -10^6 \leq a, x_i \leq 10^6

输出格式

一行,一个正整数,表示最小的总行走距离。

题目描述

Vasya takes part in the orienteering competition. There are n n checkpoints located along the line at coordinates x1,x2,...,xn x_{1},x_{2},...,x_{n} . Vasya starts at the point with coordinate a a . His goal is to visit at least n1 n-1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.

Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.

输入格式

The first line of the input contains two integers n n and a a ( 1<=n<=100000 1<=n<=100000 , 1000000<=a<=1000000 -1000000<=a<=1000000 ) — the number of checkpoints and Vasya's starting position respectively.

The second line contains n n integers x1,x2,...,xn x_{1},x_{2},...,x_{n} ( 1000000<=xi<=1000000 -1000000<=x_{i}<=1000000 ) — coordinates of the checkpoints.

输出格式

Print one integer — the minimum distance Vasya has to travel in order to visit at least n1 n-1 checkpoint.

样例 #1

样例输入 #1

3 10
1 7 12

样例输出 #1

7

样例 #2

样例输入 #2

2 0
11 -10

样例输出 #2

10

样例 #3

样例输入 #3

5 0
0 0 1000 0 0

样例输出 #3

0

提示

In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 1210=2 12-10=2 ) and then proceed to the second one (distance is 127=5 12-7=5 ). The total distance is equal to 2+5=7 2+5=7 .

In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point 10 -10 .