201010: [AtCoder]ARC101 C - Candles

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

There are $N$ candles placed on a number line. The $i$-th candle from the left is placed on coordinate $x_i$. Here, $x_1 < x_2 < ... < x_N$ holds.

Initially, no candles are burning. Snuke decides to light $K$ of the $N$ candles.

Now, he is at coordinate $0$. He can move left and right along the line with speed $1$. He can also light a candle when he is at the same position as the candle, in negligible time.

Find the minimum time required to light $K$ candles.

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq K \leq N$
  • $x_i$ is an integer.
  • $|x_i| \leq 10^8$
  • $x_1 < x_2 < ... < x_N$

Input

Input is given from Standard Input in the following format:

$N$ $K$
$x_1$ $x_2$ $...$ $x_N$

Output

Print the minimum time required to light $K$ candles.


Sample Input 1

5 3
-30 -10 10 20 50

Sample Output 1

40

He should move and light candles as follows:

  • Move from coordinate $0$ to $-10$.
  • Light the second candle from the left.
  • Move from coordinate $-10$ to $10$.
  • Light the third candle from the left.
  • Move from coordinate $10$ to $20$.
  • Light the fourth candle from the left.

Sample Input 2

3 2
10 20 30

Sample Output 2

20

Sample Input 3

1 1
0

Sample Output 3

0
  • There may be a candle placed at coordinate $0$.

Sample Input 4

8 5
-9 -7 -4 -3 1 2 3 4

Sample Output 4

10

Input

题意翻译

## 题意描述 Lin在跳出实验室时遇到了一扇门需要打开 这扇门有$N$个开关,第$i$个开关在坐标$x_i$处,一开始Lin在坐标$0$处 当打开至少$K$个开关时,这扇门就会打开 如果Lin的移动速度为$1$,打开开关忽略不计,问Lin至少要花费多少时间才能使这扇门打开 ## 说明/提示 $\begin{array}{l}1\le N\le 10^5\\1\le K\le N\\|x_i|\le 10^8\\x_i\text{单调递增}\end{array}$ **样例1解释** 按顺序打开位置在$-10,10,20$的开关即可 **样例3解释** 开关就在坐标$0$,根本不用移动

加入题单

上一题 下一题 算法标签: