OpenKattis
Saudi IOI: Intensive Selection Contest 1 (Greedy)

Start

2018-12-31 12:15 CET

Saudi IOI: Intensive Selection Contest 1 (Greedy)

End

2018-12-31 15:45 CET
The end is near!
Contest is over.
Not yet started.
Contest is starting in -2182 days 16:10:25

Time elapsed

3:30:00

Time remaining

0:00:00

Problem D
The Library

You are working a a library and want to return a number of books to the shelves. The shelves are placed along the $x$-axis. Given at what positions each book should be placed (an $x$-coordinate between $-1\, 000$ and $1\, 000$) and the maximum number of books you can carry at the same time, determine the shortest distance you must go to return all the books. The books that should be returned are originally on position 0. You do not need to go back to position $0$ after returning the last book.

Input

The first line contains two integers – the number of books to be returned $N$ (where $1 \le N \le 100$) and the number of books you can carry at the same time $K$ (where $1 \le K \le 100$).

This is followed by $N$ lines, each containing a single integer – the $x$-coordinate of a book to be returned. This will be between $-1\, 000$ and $1\, 000$.

Output

The program should output a single line with an integer – the minimum distance you must go to return all the books.

Scoring

Your program will be tested on $5$ test cases. For each test case it passes, you get $20$ points.

In one testcase, $N \le 10$.

Explanation of Sample 1

For example, you could start by taking the books to be placed at positions $3$ and $4$. Afterwards, you go back to get the book to be placed at position $1$, and finally you go back to get the book to be placed at position $-4$.

The total distance would be $4 + 4 + 1 + 1 + 4 = 14$.

Sample Input 1 Sample Output 1
4 2
3
1
4
-4
14