CF472B.Design Tutorial: Learn from Life

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

创建任务的一种方法是向生活学习。你可以选择一些现实生活中的经历,将其形式化,从而得到一个新任务。

让我们思考一个现实生活中的场景:许多人正在电梯前等待,每个人想去某个特定的楼层。我们可以将该场景形式化如下:有 nn 个人站在一楼,第 ii 个人想去第 fif_i 层。不幸的是,只有一部电梯,其容量为 kk(即同一时刻最多可容纳 kk 人)。初始时电梯位于一楼。电梯从第 aa 层移动到第 bb 层需要 ∣a−b∣|a - b| 秒(我们不计算人员进出电梯所需的时间)。

将所有人运送到各自的目标楼层,并最终将电梯返回一楼,所需的最短时间(以秒为单位)是多少?

输入格式

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.

第一行包含两个整数 nn 和 kk(1≤n,k≤20001 \leq n, k \leq 2000)—— 分别表示人数和电梯的最大载客量。

第二行包含 nn 个整数:f1, f2, …, fnf_1,\ f_2,\ \dots,\ f_n(2≤fi≤20002 \leq f_i \leq 2000),其中 fif_i 表示第 ii 个人的目标楼层。

输出格式

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. 电梯搭载第 1 号和第 2 号人员。
  2. 电梯前往 2 楼。
  3. 两人均离开电梯。
  4. 电梯返回 1 楼。
  5. 然后电梯搭载第 3 号人员。
  6. 电梯前往 2 楼。
  7. 电梯接上第 2 号人员。
  8. 然后电梯前往 3 楼。
  9. 第 2 号人员离开电梯。
  10. 接着电梯前往 4 楼,第 3 号人员离开电梯。
  11. 电梯返回 1 楼。

输入解题思路,AI测评打分。不知道怎么写?

首页