QOJ.ac

QOJ

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

#2545. 球与盒子的游戏

Statistiques

有 $N$ 个盒子和 $N$ 个球。你正在进行一场游戏,规则如下:

盒子按 $1$ 到 $N$ 的整数编号,球也按 $1$ 到 $N$ 的整数编号。第 $i$ 个盒子最初包含球 $P_i$。

每个盒子要么是打开的,要么是关闭的。最初,所有盒子都是关闭的。

游戏进行两轮球的移动。在每一轮中,你执行以下操作:

  1. 选择零个或多个盒子并将其打开。在第一轮中打开第 $i$ 个盒子需要支付 $A_i$ 枚硬币。在第二轮中打开第 $i$ 个盒子需要支付 $B_i$ 枚硬币。
  2. 在打开的盒子之间自由移动球。但是,移动完成后,每个盒子必须恰好包含一个球。
  3. 关闭所有打开的盒子。

两轮结束后,对于每个 $i$,第 $i$ 个盒子必须包含球 $i$。求完成游戏所需支付的最小硬币总数。

输入格式

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

第二行包含 $N$ 个整数 $P_1, P_2, \dots, P_N$:其中 $P_i$ 是最初放置在第 $i$ 个盒子中的球的编号 ($1 \le P_i \le N$,$P_i \neq P_j$ 当 $i \neq j$)。

第三行包含 $N$ 个整数 $A_1, A_2, \dots, A_N$:其中 $A_i$ 是在第一轮中打开第 $i$ 个盒子的价格 ($1 \le A_i \le 10^9$)。

第四行包含 $N$ 个整数 $B_1, B_2, \dots, B_N$:其中 $B_i$ 是在第二轮中打开第 $i$ 个盒子的价格 ($1 \le B_i \le 10^9$)。

输出格式

输出一个整数:两轮结束后,使得第 $i$ 个盒子中包含球 $i$ 所需支付的最小硬币总数。

样例

输入 1

5
5 3 2 1 4
3 8 3 5 11
9 3 7 6 4

输出 1

28

输入 2

1
1
1000000000
1000000000

输出 2

0

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.