QOJ.ac

QOJ

Time Limit: 0.2 s Memory Limit: 32 MB Total points: 100

#6708. 电梯停靠计划

Statistics

ZSoft Corp. 是一家位于高科大厦的软件公司,大厦里的员工工作非常勤奋。但大厦里的电梯总是让他们抓狂。为什么呢?因为高科大厦里只有一部电梯,而大厦里有数百家公司。每天早上,人们都必须浪费大量时间等待电梯。

ZSoft 的聪明人 Hal 想要改变这种状况。他想找到一种方法让电梯运行得更有效率,但这并非易事。

高科大厦共有 $31$ 层。电梯上升一层需要 $4$ 秒。这意味着:

  • 如果电梯从 1 楼直达 31 楼且中途不停,耗时 $(31-1) \times 4=120$ 秒。
  • 电梯每次停靠耗时 $10$ 秒。因此,如果电梯在每一层都停,将耗时 $30 \times 4+29 \times 10 = 410$ 秒(无需计算在 31 楼的停靠时间)。
  • 员工步行上下楼一层需要 $20$ 秒。他们从 1 楼走到 31 楼需要 $30 \times 20 = 600$ 秒。

显然,步行并不是一个好主意。因此,有些人选择乘坐电梯到达离他们办公室最近的楼层。

经过长时间的思考,Hal 终于找到了改善这种情况的方法。他告诉电梯管理员他的想法:首先,电梯管理员询问人们想去哪些楼层。然后,他将设计一个停靠方案,使得最后一个人到达其目标楼层的时间最小化。

例如,如果要求电梯在 4 楼、5 楼和 10 楼停靠,停靠方案将是:电梯在 4 楼和 10 楼停靠。因为电梯将在 $3 \times 4 = 12$ 秒时到达 4 楼,然后停靠 $10$ 秒,接着在 $3 \times 4+10+6 \times 4 = 46$ 秒时到达 10 楼。想去 4 楼的人将在 $12$ 秒到达办公室,想去 5 楼的人将在 $12+20 = 32$ 秒到达,而想去 10 楼的人将在 $46$ 秒到达。因此,最后一个人到达办公室需要 46 秒。这对所有人来说都是一个不错的方案。

现在,你需要编写一个程序来帮助电梯管理员设计停靠方案,使得最后一个人到达其目标楼层的时间最小化。

输入格式

输入包含多个测试用例。每个测试用例占一行,格式如下:

  • $n$ $f_1$ $f_2$ $\ldots$ $f_n$

这意味着电梯总共需要停靠 $n$ 个楼层,$n = 0$ 表示测试结束。$f_1$ $f_2$ $\ldots$ $f_n$ 是电梯需要停靠的楼层($n \leq 30$,$2 \leq f_1 < f_2 \ldots f_n \leq 31$)。每个数字由一个空格分隔。

输出格式

对于每个测试用例,第一行输出最后一个人到达所需的时间,第二行输出停靠的楼层。请注意,第二行开头是停靠楼层的总数。可能存在多种方案,任何合适的方案均可接受。不允许有多余的空格。

样例

输入 1

3 4 5 10
1 2
0

输出 1

46
2 4 10
4
1 2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.