QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#15897. 反人类电梯

Estadísticas

如今,所有的设备都是智能的:智能手机、智能音箱、智能灯泡,甚至智能电梯。机器正在崛起。

人类反抗军的总部设在一栋摩天大楼里。然而,智能电梯试图在不暴露自己的情况下,尽可能地拖慢人们的速度。

摩天大楼里有 $n$ 个人在不同的楼层等电梯。每个人都想去另一个楼层。每个人的目的地楼层都与其他所有人的目的地楼层以及所有人的起始楼层不同。最开始,电梯位于第一层。它每单位时间移动一个楼层。每当电梯门打开时,它会选择下一个楼层并直接前往。电梯既可以前往尚未登梯的人的起始楼层去接他们,也可以前往已经在电梯里的人的目的地楼层去送他们。请注意,即使对于已经在电梯里的人,电梯也不会在中间楼层停留。乘客登梯和下梯的时间可以忽略不计。电梯足够大,可以同时容纳所有人。

电梯的目标是最大化将所有乘客送达其目的地楼层的总时间。求从第一层出发,直到最后一名乘客下梯为止的最大总时间。电梯不需要返回第一层。

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 10\,000$)。接下来是测试用例的描述。

每个测试用例的第一行包含一个整数 $n$,表示人数 ($1 \le n \le 10^5$)。

接下来的 $n$ 行,每行包含两个整数 $s_i$ 和 $f_i$ ($2 \le s_i, f_i \le 10^9$),分别表示第 $i$ 个人的起始楼层和目的地楼层。输入中的所有 $2n$ 个楼层两两不同。

保证所有测试用例中 $n$ 的总和不超过 $10^5$。

输出格式

对于每个测试用例,输出运送所有人所需的最大时间。

样例

输入 1

3
1
5 3
2
2 7
8 4
2
10 8
6 3

输出 1

6
21
21

说明

在第一个测试用例中,只有一个人。访问楼层的顺序为 $1 \to 5 \to 3$,时间为 $6$。

在第二个测试用例中,其中一个正确的顺序是 $1 \to 8 \to 2 \to 7 \to 4$,时间为 $21$。

在第三个测试用例中,其中一个正确的顺序是 $1 \to 10 \to 6 \to 3 \to 8$,时间为 $21$。

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.