cswork / OA打开练习工作台

AmazonOA #177

Find Minimum Time

估计中等可在线判题

考点(AI 标注)双指针滑窗贪心调度

There is one apple at each of several distinct integer coordinates. Starting from 0, you move 1 unit per second and may turn around at any time; an apple is eaten as soon as you reach it. Find the shortest time to eat at least k apples.

输入格式

The first line contains n k; the second line contains the coordinates. 1≤n≤100000; 1≤k≤n; coordinates are in −10^8..10^8 and pairwise distinct.

输出格式

Output a single integer, the answer.

样例 1

输入:

3 3
-20 5 10

输出:

40

样例 2

输入:

2 1
0 5

输出:

0

样例 3

输入:

3 2
-9 -3 4

输出:

9

样例说明

The answers are 40, 0 and 9.