Codeforces Round 270
B
Design Tutorial: Learn from Life
Codeforces
1300
原题
← AC →
翻译中…

One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.

翻译中…

Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following way. We have $*n*$ people standing on the first floor, the $*i*$-th person wants to go to the $*f*_{*i*}$-th floor. Unfortunately, there is only one elevator and its capacity equal to $*k*$ (that is at most $*k*$ people can use it simultaneously). Initially the elevator is located on the first floor. The elevator needs $|*a* - *b*|$ seconds to move from the $*a*$-th floor to the $*b*$-th floor (we don't count the time the people need to get on and off the elevator).

翻译中…

What is the minimal number of seconds that is needed to transport all the people to the corresponding floors and then return the elevator to the first floor?

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*k*$ $(1 ≤ *n*, *k* ≤ 2000)$ — the number of people and the maximal capacity of the elevator.

翻译中…

The next line contains $*n*$ integers: $*f*_{1}, *f*_{2}, ..., *f*_{*n*}$ $(2 ≤ *f*_{*i*} ≤ 2000)$, where $*f*_{*i*}$ denotes the target floor of the $*i*$-th person.

翻译中…

Output

翻译中…

Output a single integer — the minimal time needed to achieve the goal.

翻译中…

Note

翻译中…

In first sample, an optimal solution is:

翻译中…
  1. The elevator takes up person #1 and person #2.
  2. It goes to the 2nd floor.
  3. Both people go out of the elevator.
  4. The elevator goes back to the 1st floor.
  5. Then the elevator takes up person #3.
  6. And it goes to the 2nd floor.
  7. It picks up person #2.
  8. Then it goes to the 3rd floor.
  9. Person #2 goes out.
  10. Then it goes to the 4th floor, where person #3 goes out.
  11. The elevator goes back to the 1st floor.
翻译中…

样例

Input #1
3 2
2 3 4
Output #1
8
InputCopy OutputCopy
Input #2
4 2
50 100 50 100
Output #2
296
InputCopy OutputCopy
Input #3
10 3
2 2 2 2 2 2 2 2 2 2
Output #3
8
InputCopy OutputCopy
题目信息
题号
472B
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。