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?
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?
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
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted