CF709B.Checkpoints

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya takes part in the orienteering competition. There are nn checkpoints located along the line at coordinates x1,x2,...,xnx_{1},x_{2},...,x_{n} . Vasya starts at the point with coordinate aa . His goal is to visit at least n1n-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 nn and aa ( 1<=n<=1000001<=n<=100000 , 1000000<=a<=1000000-1000000<=a<=1000000 ) — the number of checkpoints and Vasya's starting position respectively.

The second line contains nn integers x1,x2,...,xnx_{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 n1n-1 checkpoint.

输入输出样例

  • 输入#1

    3 10
    1 7 12
    

    输出#1

    7
    
  • 输入#2

    2 0
    11 -10
    

    输出#2

    10
    
  • 输入#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=212-10=2 ) and then proceed to the second one (distance is 127=512-7=5 ). The total distance is equal to 2+5=72+5=7 .

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

首页