Robot
In the country of Olympia, today is a holiday!
The only post office on Olympic Street is bustling with gifts that need to be delivered to their recipients as quickly as possible. Today, N
gifts have arrived, and the i-th
gift is destined for the house numbered h[i]
. Multiple gifts may be addressed to the same house.
The post office is situated at the start of Olympic Street. To the right, along a straight road, are houses numbered starting from 1
; the i-th
house is located i
kilometers from the post office. For delivery, a special postal robot is used in an experimental mode, capable of carrying up to K
items at once. Loading or unloading a single gift takes one minute, and two gifts cannot be loaded or unloaded simultaneously. The robot travels one kilometer in one minute.
Task
Write a program that, based on the details of each gift and the robot's capabilities, calculates the minimum time in minutes for the robot to deliver all the gifts to their recipients and return to the post office. Initially, all gifts and the robot are at the post office.
Input Data
The first line of input contains two integers N
and K
(1 ≤ N ≤ 10^5, 1 ≤ K ≤ 10^3)
— the number of gifts at the post office and the maximum number of items the robot can carry at once. The second line contains N
integers separated by spaces: the i-th
number is h[i]
(1 ≤ h[i] ≤ 10^6)
— the house number to which the i-th
gift needs to be delivered. It is guaranteed that houses with these numbers are located on Olympic Street.
Output Data
The output should be a single integer — the minimum time in minutes for the robot to deliver all the gifts and return to the post office.
Evaluation
The test set consists of 4 blocks, each with the following conditions:
25% of points:
1 ≤ N ≤ 10, 1 ≤ K ≤ 5, 1 ≤ h[i] ≤ 10^2
.25% of points:
1 ≤ N ≤ 10^3, 1 ≤ K ≤ 10^2, 1 ≤ h[i] ≤ 10^4
.25% of points:
1 ≤ N ≤ 10^5, 1 ≤ K ≤ 10^3, 1 ≤ h[i] ≤ 10^4
.25% of points:
1 ≤ N ≤ 10^5, 1 ≤ K ≤ 10^3, 1 ≤ h[i] ≤ 10^6
.
Explanation. Let's number the gifts from 1 to 7. An optimal delivery plan might look like this:
• 2 minutes: loading gifts 5 and 6 (both for house 1),
• 1 minute: traveling from the post office to house 1,
• 2 minutes: unloading gifts 5 and 6,
• 1 minute: returning from house 1 to the post office,
• 2 minutes: loading gifts 2 and 7 (gift 2 for house 9, gift 7 for house 3),
• 9 minutes: traveling from the post office to house 9,
• 1 minute: unloading gift 2,
• 6 minutes: traveling from house 9 to house 3,
• 1 minute: unloading gift 7,
• 3 minutes: returning from house 3 to the post office,
• 3 minutes: loading gifts 1, 3, and 4 (gifts 1 and 3 for house 3, gift 4 for house 2),
• 2 minutes: traveling to house 2,
• 1 minute: unloading gift 4,
• 1 minute: traveling from house 2 to house 3,
• 2 minutes: unloading gifts 1 and 3,
• 3 minutes: returning from house 3 to the post office.