Checkpoint running
InterviewTime limit1sMemory limit1024 MB
Given N checkpoint positions on a line and a trip limit K, find the minimum total distance to visit all checkpoints, returning to the origin after each trip of at most K checkpoints.
Problem
Chulsoo entered a checkpoint running race. In this race, a runner starts at the starting point, checks every checkpoint on the road at least once, and returns to the starting point. The starting point is at the origin, and checkpoints are placed on a straight road. The -th checkpoint is at coordinate .
The race has a special rule. Before returning to the starting point, a runner can check at most checkpoints. For example, if is , a runner starts from the starting point, checks checkpoints, returns to the starting point, and then runs toward another checkpoint. A runner may also pass a checkpoint without checking it.
Help Chulsoo check all checkpoints while minimizing the total distance traveled.
Input
The first line contains the number of checkpoints and the maximum number of checkpoints that can be checked in one trip.
The next lines each contain the position of a checkpoint.
Output
Print the minimum total distance Chulsoo must travel to check all checkpoints.
Constraints
All given numbers are integers.