QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 512 MB 총점: 100

#15812. 简单珠穆朗玛峰

통계

珠穆朗玛峰的南坡上有 $n$ 名登山者,他们所处位置的高度分别为 $h_1, h_2, \dots, h_n$;北坡上也有 $n$ 名登山者,他们所处位置的高度分别为 $g_1, g_2, \dots, g_n$。

如果对于每一个可能的高度,南坡和北坡上处于该高度的登山者人数都相等,则称登山者的这种安排是安全的。登山者们希望调整到一个安全的安排以度过暴风雨。为此,每位登山者都可以在自己所在的斜坡上改变自己的位置(不能去往另一个斜坡)。将位置高度从 $a$ 改变到 $b$,登山者需要消耗 $|b - a|$ 单位的能量。由于这次登山注定十分艰难,登山者们希望消耗最少的总能量来达到安全安排。你的任务是计算出这个最小总能量。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 3 \cdot 10^5$) —— 登山者的数量。

第二行包含 $n$ 个整数 $h_i$ ($1 \le h_i \le 10^9$) —— 南坡登山者所处位置的高度。

第三行包含 $n$ 个整数 $g_i$ ($1 \le g_i \le 10^9$) —— 北坡登山者所处位置的高度。

输出格式

输出一行,表示登山者为了达到安全安排所需消耗的最小总能量。

样例

输入样例 1

2
1 7
4 3

输出样例 1

5

输入样例 2

3
1 2 2
1 2 1

输出样例 2

1

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.