QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 10

#6586. Żarówki

الإحصائيات

巴扎塔尔新家的装修工程接近尾声。只剩下在 $n$ 个房间中的每个房间拧入一个灯泡。对于每个房间,他都确定了足以充分照亮该房间的灯泡的最小功率。

巴扎塔尔买了 $n$ 个灯泡,但现在他发现它们并没有完全满足他的期望。也许无法充分照亮所有房间,或者某些灯泡的功率可能不必要地大。因此,巴扎塔尔决定去商店更换一些灯泡,以便能够充分照亮所有房间,同时尽可能地限制灯泡的总功率。商店有任意正功率的灯泡。巴扎塔尔的背包最多可以携带 $k$ 个灯泡进行更换——这是他愿意更换的最大灯泡数量。

帮助巴扎塔尔选择需要更换哪些灯泡,以便所有房间都得到充分照明,同时最大限度地限制灯泡的总功率。

输入格式

输入的第一行包含两个整数 $n$ 和 $k$ ($1 \le k \le n \le 500\,000$),分别表示房间数(也是灯泡数)和巴扎塔尔背包中可以容纳的灯泡数量。房间编号从 1 到 $n$。输入的第二行包含 $n$ 个整数 $p_{1}$, $p_{2}$, ..., $p_{n}$ ($1 \le p_{i} \le 10^{9}$),表示巴扎塔尔当前拥有的灯泡的功率。输入的第三行包含 $n$ 个整数 $w_{1}$, $w_{2}$, ..., $w_{n}$ ($1 \le w_{i} \le 10^{9}$),表示各个房间的照明要求——在房间 $i$ 中应拧入功率至少为 $w_{i}$ 的灯泡。

输出格式

如果无法通过更换最多 $k$ 个灯泡来充分照亮所有房间,则输出 NIE。否则,输出一个整数,表示更换最多 $k$ 个灯泡后用于照亮房屋的所有灯泡的最小总功率。

示例

输入

6 2
12 1 7 5 2 10
1 4 11 4 7 5

输出

33
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.