409024: GYM103416 D Delivery

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Deliverytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given a sequence of delivery points $$$x$$$ of length $$$n$$$ and the integer number $$$k$$$.

Delivery point is an integer number $$$x_i$$$ in the range of $$$[-10^9; 10^9]$$$ (i.e. $$$-10^9 \le x_i \le 10^9$$$).

Find the minimum distance of delivering any $$$k$$$ orders. Initially you are at origin $$$0$$$.

The distance between $$$x_i$$$ and $$$x_j$$$ is the absolute difference between them |$$$x_i$$$ - $$$x_j$$$|.

Input

The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^6$$$, $$$1 \le k \le n$$$).

The second line of the input contains $$$n$$$ integer numbers $$$x_1, x_2, \dots, x_n$$$ ($$$-10^9 \le x_i \le 10^9$$$).

Output

Print the minimum distance of delivering any $$$k$$$ orders.

ExampleInput
4 3
-5 -4 3 7
Output
11
Note

The path (0, 3, -4, -5) gives the minimum distance: |3-0|+|-4-3|+|-5-(-4)| = 11

加入题单

算法标签: