QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100

#12158. 圣诞老人

統計

圣诞老人有一项艰巨的任务:他不仅要按时把礼物送到所有孩子手中,还必须确保每个孩子都能得到合适的礼物。好孩子会收到玩具、算法竞赛决赛的门票或自行车,而淘气的孩子则会得到一块煤炭或一套 Windows Vista 安装程序。

为了按计划完成任务,今晚圣诞老人必须给恰好 $K$ 个孩子送去礼物,但精灵们忘记在礼物上贴上收件人的名字了!圣诞老人必须自己解决这个问题——从 $N$ 个礼物中选择 $K$ 个,并将它们分配给 $M$ 个等待礼物的孩子中的 $K$ 个。

圣诞老人知道每个礼物的质量 $j_i$(可能是正数或非正数),以及每个孩子的友善度 $g_i$(也可能是正数或非正数)。

圣诞老人希望最大化礼物分配的公平性:如果将礼物 $i$ 分配给孩子 $k$,则总公平性增加 $j_i \cdot g_k$。

你能帮他确定分配恰好 $K$ 个礼物所能达到的最大公平性吗?

输入格式

第一行包含三个整数 $K, N$ 和 $M$ ($1 \le K, N, M \le 200\,000, K \le \min(N, M)$),分别表示圣诞老人今天想要送出的礼物数量、仓库中的礼物总数以及等待礼物的孩子总数。

第二行包含 $N$ 个整数 $j_1, \dots, j_N$ ($-10^6 \le j_i \le 10^6$),表示礼物的质量。

第三行包含 $M$ 个整数 $g_1, \dots, g_M$ ($-10^6 \le g_i \le 10^6$),表示孩子的友善度。

输出格式

输出一个整数——分配 $K$ 个礼物所能达到的最大公平性。

样例

样例输入 1

3 3 5
2 -2 4
-10 0 -2 3 2

样例输出 1

36

样例输入 2

1 4 4
0 0 0 0
2 4 -2 0

样例输出 2

0

样例输入 3

1 2 2
1 2
-1 -2

样例输出 3

-1

说明

样例解释:

在第一个样例中,所有礼物的分配方式如下: 质量为 $2$ 的礼物应给友善度为 $2$ 的孩子。 质量为 $-2$ 的礼物应给友善度为 $-10$ 的孩子。 * 质量为 $4$ 的礼物应给友善度为 $3$ 的孩子。

总公平性为 $2 \cdot 2 + (-2) \cdot (-10) + 4 \cdot 3 = 36$。

在第二个样例中,仓库里的所有礼物都非常平庸,所以无论选择哪一个或分配给谁,公平性总是 $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.