Under construction

Still being built. Things may change

Library

Time limit2sMemory limit128 MB

Summary
Find the minimum total steps for a librarian starting at 0 to deliver books to their positive or negative integer positions while carrying at most M books per trip.
Level

Medium5 of 10

Topics
Greedy, Sorting, Math, Simulation
Solved
No attempts yet

Problem

Sejun works at a library. After closing time, he must return books that people left out of place to their original positions.

Sejun starts at coordinate 0, and all books are initially at coordinate 0. Given the original integer coordinate of each book, compute the minimum number of steps needed to put every book back.

Sejun moves by 1 coordinate per step. After placing all books, he does not need to return to coordinate 0. He can carry at most M books at once.

Input

The first line contains N, the number of books, and M, the maximum number of books Sejun can carry at once.

The second line contains the original positions of the books. N and M are natural numbers at most 50. Every position is nonzero, and its absolute value is an integer at most 10,000.

Output

Print the minimum number of steps on the first line.

Examples4

  1. Example 1

    Input
    7 2
    -37 2 -6 -39 -29 11 -28
    
    Expected output
    131
    
  2. Example 2

    Input
    8 3
    -18 -9 -4 50 22 -26 40 -45
    
    Expected output
    158
    
  3. Example 3

    Input
    6 2
    3 4 5 6 11 -1
    
    Expected output
    29
    
  4. Example 4

    Input
    1 50
    1
    
    Expected output
    1