QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100

#11739. 电梯

统计

你有一项非常重要的工作:负责新摩天大楼里的一部电梯。

有 $n$ 个人会来到位于 0 层的地下停车场,等待电梯将他们送到某一层楼。形式化地说,第 $i$ 个人在时刻 $t_i$ 到达电梯,并希望到达 $a_i$ 层。电梯的容量是无限的,即在任何时刻使用电梯的人数没有限制。所有的 $t_i$ 互不相同。只要电梯在 0 层,乘客总是会进入电梯。

电梯使用以下算法:它会停在 0 层,直到你发出指令让它去运送乘客,然后它会移动到它需要到达的最高楼层(即当前电梯内所有乘客目的地楼层 $a_i$ 中的最大值),在此过程中分发乘客,最后返回停车场。电梯移动到下一层(或上一层)需要 1 个单位时间。电梯开关门以及乘客进出的时间忽略不计。在时刻 0,电梯位于 0 层。

你希望最小化电梯在运送完所有人后返回 0 层的时刻。

输入格式

输入包含一个或多个测试用例。

每个测试用例的第一行包含一个整数 $n$:乘客数量($1 \le n \le 2 \cdot 10^5$)。

接下来的 $n$ 行,每行包含两个空格分隔的整数 $t_i$ 和 $a_i$:第 $i$ 位乘客到达电梯的时刻,以及第 $i$ 位乘客的目的地楼层($1 \le t_i, a_i \le 10^9$)。

在同一个测试用例中,所有的 $t_i$ 互不相同,且输入中乘客按 $t_i$ 的升序排列。

所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。测试用例之间没有特殊的分割符。

输出格式

对于每个测试用例,输出一个整数:电梯在运送完所有人后返回 0 层的最小可能时刻。

样例

输入 1

3
1 9
2 6
15 6
3
1 9
2 6
15 8

输出 1

31
33

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#205EditorialOpen题解jiangly2025-12-13 00:12:24View

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.