OpenKattis
Träning för PO-final 2015

Start

2015-01-03 00:00 CET

Träning för PO-final 2015

End

2015-01-29 00:00 CET
The end is near!
Session is over.
Not yet started.
Session is starting in -3610 days 15:03:43

Time elapsed

624:00:00

Time remaining

0:00:00

Problem A
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