QOJ.ac

QOJ

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

#18177. MIPT Campus

统计

Dolgoprudny 中属于 MIPT 的一部分对学生来说非常便利。长长的 Pervomayskaya 街将 Dolgoprudny 分成了两部分:大学(教学)楼在这条街的左侧,宿舍在这条街的右侧。假设 $0X$ 轴与这条街共线。Pervomayskaya 街的宽度以及建筑物到街道的距离都可以忽略不计,因此你可以将这个模型视为一维的。

MIPT 恰好有 $n$ 名学生上课。每天早晨,他们每个人都从自己的宿舍出发,穿过 Pervomayskaya 街,前往自己的教学楼。第 $i$ 名学生住在 $x$ 坐标为 $a_i$ 的宿舍,在 $x$ 坐标为 $b_i$ 的教学楼上课。学生只能在人行横道处过街。目前有 $m$ 个垂直于 $0X$ 轴的人行横道,它们位于 $x$ 坐标为 $c_1, c_2, \dots, c_m$ 的点处。在前往教学楼的过程中,学生总是选择最短的路径。

最近,MIPT 青年委员会得出结论,人行横道的数量对学生来说不够。他们游说并提出了一项倡议,在 Pervomayskaya 街的任意点新建一个人行横道。现在,他们希望新建一个人行横道,使得所有学生从宿舍到教学楼的步行距离之和最小。你的任务是求出这个最小值。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 5 \cdot 10^5$) —— 在 MIPT 上课的学生人数。

接下来的 $n$ 行,每行包含两个整数 $a_i, b_i$ ($1 \le a_i, b_i \le 10^9$) —— 第 $i$ 名学生的宿舍和教学楼的坐标。

下一行包含一个整数 $m$ ($0 \le m \le 5 \cdot 10^5$) —— 现有的人行横道数量。

最后一行包含 $m$ 个互不相同的整数 $c_1, c_2, \dots, c_m$ ($1 \le c_i \le 10^9$) —— 现有的人行横道的坐标。

输出格式

输出单行一个整数 —— 在新建一个人行横道后,学生必须步行的最小距离之和。可以证明,答案总是整数。

样例

输入 1

2
5 10
20 30
0

输出 1

35

输入 2

2
5 10
10 20
1
2

输出 2

15

输入 3

2
5 10
20 30
1
11

输出 3

17

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.