题库练习 Design Tutorial: Learn from Life
← 上一题 下一题 →

A9598 | Design Tutorial: Learn from Life

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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?

输入格式

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?

输出格式

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

输入输出样例

输入 #1
3 2
2 3 4
输出 #1
8
输入 #2
4 2
50 100 50 100
输出 #2
296
输入 #3
10 3
2 2 2 2 2 2 2 2 2 2
输出 #3
8
C++ 编辑器
输入
输出