B - Collecting Balls (Easy Version) 解説 /

実行時間制限: 2 sec / メモリ制限: 256 MB

配点: 200

問題文

xy 平面上に N 個のボールがあります。このうち i 番目のボールの位置は (x_i, i) です。 したがって、N 本の直線 y = 1, y = 2, ..., y = N の上にそれぞれ 1 個ずつボールがあることになります。

すぬけ君は、これらのボールを回収するために、タイプ A, B のロボットを N 台ずつ用意しました。 さらに、タイプ A のロボットのうち i 台目のものを位置 (0, i) に、タイプ B のロボットのうち i 台目のものを位置 (K, i) に設置しました。 したがって、N 本の直線 y = 1, y = 2, ..., y = N の上にそれぞれ 1 台のタイプ A のロボットと、1 台のタイプ B のロボットが設置されたことになります。

それぞれのタイプのロボットは起動されると以下のように動作します。

  • タイプ A のロボットは、位置 (0, a) で起動されると、直線 y = a 上にあるボールの位置まで移動し、ボールを回収してもとの位置 (0, a) に戻って停止する。そのようなボールが存在しない場合は何もせずに停止する。
  • タイプ B のロボットは、位置 (K, b) で起動されると、直線 y = b 上にあるボールの位置まで移動し、ボールを回収してもとの位置 (K, b) に戻って停止する。そのようなボールが存在しない場合は何もせずに停止する。

これら 2N 台のロボットのうちいくつかを起動してボールをすべて回収するとき、ロボットの移動距離の総和として考えられる値のうち最小のものを求めてください。

制約

  • 1≦N≦100
  • 1≦K≦100
  • 0 < x_i < K
  • 入力値はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N
K
x_1 x_2 ... x_N

出力

ロボットの移動距離の総和として考えられる値のうち最小のものを出力せよ。


入力例 1

1
10
2

出力例 1

4

ボールが 1 個だけあり、タイプ A および B のロボットが 1 つずつあります。

タイプ A のロボットを用いてボールを回収すると、ボールの位置までの移動距離は 2 であり、もとの位置に戻るための移動距離も 2 であるので、合計の移動距離は 4 となります。

同様にタイプ B のロボットを用いてボールを回収したときの移動距離の合計を計算すると 16 となります。

よって、タイプ A のロボットを用いて回収すると合計の移動距離が最小となり、そのときの移動距離である 4 を出力します。


入力例 2

2
9
3 6

出力例 2

12

1 つめのボールはタイプ A のロボットで、2 つめのボールはタイプ B のロボットで回収すると移動距離が最小となります。


入力例 3

5
20
11 12 9 17 12

出力例 3

74

Score : 200 points

Problem Statement

There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.

In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.

When activated, each type of robot will operate as follows.

  • When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

  • When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq K \leq 100
  • 0 < x_i < K
  • All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
K
x_1 x_2 ... x_N

Outputs

Print the minimum possible total distance covered by robots.


Sample Input 1

1
10
2

Sample Output 1

4

There are just one ball, one type-A robot and one type-B robot.

If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.

Similarly, if the type-B robot is used, the total distance covered will be 16.

Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.


Sample Input 2

2
9
3 6

Sample Output 2

12

The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.


Sample Input 3

5
20
11 12 9 17 12

Sample Output 3

74