AtCoder Beginner Contest 107
C
Candles
AtCoder
⌀ 947
原题
← BD →
翻译中…

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.

翻译中…

样例

Input #1
5 3
-30 -10 10 20 50
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.
Input #2
3 2
10 20 30
Output #2
20
Input #3
1 1
0
Output #3
0
- There may be a candle placed at coordinate $0$.
Input #4
8 5
-9 -7 -4 -3 1 2 3 4
Output #4
10
题目信息
题号
arc101_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。