QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100

#2541. 硬币与盒子

Statistiques

在坐标轴上有 $N$ 个盒子和 $N$ 枚硬币。第 $i$ 个盒子的坐标为 $B_i$,第 $j$ 枚硬币的坐标为 $C_j$。你从坐标为 $0$ 的点出发,可以在坐标轴上自由移动。

如果你到达一个有硬币的位置,你可以捡起那枚硬币。你可以携带任意数量的硬币。如果你到达一个有盒子的位置,你可以使用一枚硬币来打开该盒子(但你不是必须这样做)。你不能捡起已经被捡过的硬币,也不能打开已经被打开的盒子。

你的目标是打开所有 $N$ 个盒子。求你为了达成目标所需要行进的最小距离。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 10^5$)。

第二行包含 $N$ 个整数 $B_1, B_2, \dots, B_N$。其中第 $i$ 个整数是第 $i$ 个盒子的坐标 ($1 \le B_i \le 10^9$, $B_i < B_{i+1}$ 对于 $1 \le i < N$)。

第三行包含 $N$ 个整数 $C_1, C_2, \dots, C_N$。其中第 $i$ 个整数是第 $i$ 枚硬币的坐标 ($1 \le C_i \le 10^9$, $C_i < C_{i+1}$ 对于 $1 \le i < N$)。

输出格式

输出一个整数:打开所有盒子所需要行进的最小距离。

样例

样例输入 1

4
1 6 7 12
3 5 10 11

样例输出 1

21

样例输入 2

2
1 2
1 1000000000

样例输出 2

1999999998

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.