QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#9222. 价格组合

الإحصائيات

Czesław 决定组装一台属于他自己的电脑。经过深思熟虑,他选定了一套完整的配置,并列出了他需要购买的 $N$ 个组件。

当地有两家电子产品商店:AutoAGD 和 BioBezpieczniki。Czesław 清单上的第 $i$ 个组件在 AutoAGD 商店的价格为 $A_i$ PLN,在 BioBezpieczniki 商店的价格为 $B_i$ PLN。两家商店都独立提供“价格组合:买一送一”促销活动——购买两件商品时,价格较低的那件免费(价格相同时任选其一免费)。该促销活动不限次数,意味着同一位顾客可以在一家商店进行多次购买,每次都能享受该优惠。

请帮助 Czesław 以最低的总成本买齐所有组件。输出他购买所有 $N$ 个组件所需花费的最低总金额。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 200\,000$),表示 Czesław 需要购买的组件数量。

第二行包含 $N$ 个整数 $A_1, A_2, \dots, A_N$ ($1 \le A_i \le 10^9$),表示各组件在 AutoAGD 商店的价格。

第三行包含 $N$ 个整数 $B_1, B_2, \dots, B_N$ ($1 \le B_i \le 10^9$),表示各组件在 BioBezpieczniki 商店的价格。

输出格式

输出一个整数,表示 Czesław 购买所有 $N$ 个组件所需花费的最低总金额(单位为 PLN)。

样例

输入 1

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

输出 1

131

说明

Czesław 想要购买 7 个组件。他可以进行如下购买:

  • 在 AutoAGD,他购买组件 1(10 PLN)和组件 5(10 PLN),支付 10 PLN。
  • 在 AutoAGD,他购买组件 4(99 PLN)和组件 7(49 PLN),支付 99 PLN。
  • 在 BioBezpieczniki,他购买组件 2(14 PLN)和组件 3(15 PLN),支付 15 PLN。
  • 在 BioBezpieczniki,他购买组件 6,支付 7 PLN。

所有购买的总花费为 $10 + 99 + 15 + 7 = 131$ PLN。

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.