CF1876A.Helmets in Night Light
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Pak Chanek is the chief of a village named Khuntien. On one night filled with lights, Pak Chanek has a sudden and important announcement that needs to be notified to all of the n residents in Khuntien.
First, Pak Chanek shares the announcement directly to one or more residents with a cost of p for each person. After that, the residents can share the announcement to other residents using a magical helmet-shaped device. However, there is a cost for using the helmet-shaped device. For each i, if the i-th resident has got the announcement at least once (either directly from Pak Chanek or from another resident), he/she can share the announcement to at most ai other residents with a cost of bi for each share.
If Pak Chanek can also control how the residents share the announcement to other residents, what is the minimum cost for Pak Chanek to notify all n residents of Khuntien about the announcement?
帕克·查内克是名为昆田的村庄的村长。在一个灯火通明的夜晚,帕克·查内克有一项突发且重要的公告需要通知昆田村全部 n 名居民。
首先,帕克·查内克可直接将公告告知一名或多名居民,每通知一人花费为 p。此后,居民们可借助一种魔法头盔状设备将公告传递给其他居民。然而,使用该头盔状设备需付出一定代价。对每个 i,若第 i 位居民已至少一次获知该公告(无论是直接来自帕克·查内克,还是来自其他居民),则他/她最多可将公告传递给 ai 名其他居民,每次传递的花费为 bi。
若帕克·查内克还可控制居民之间公告传递的具体方式,那么他通知昆田村全部 n 名居民所需的最小总花费是多少?
输入格式
Each test contains multiple test cases. The first line contains an integer t (1≤t≤104) — the number of test cases. The following lines contain the description of each test case.
The first line contains two integers n and p (1≤n≤105; 1≤p≤105) — the number of residents and the cost for Pak Chanek to share the announcement directly to one resident.
The second line contains n integers a1,a2,a3,…,an (1≤ai≤105) — the maximum number of residents that each resident can share the announcement to.
The third line contains n integers b1,b2,b3,…,bn (1≤bi≤105) — the cost for each resident to share the announcement to one other resident.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。接下来的各行描述每个测试用例。
第一行包含两个整数 n 和 p(1≤n≤105;1≤p≤105)—— 居民人数以及 Pak Chanek 直接向一名居民发布通知的成本。
第二行包含 n 个整数 a1,a2,a3,…,an(1≤ai≤105)—— 每名居民最多可将通知转发给的居民人数。
第三行包含 n 个整数 b1,b2,b3,…,bn(1≤bi≤105)—— 每名居民将通知转发给另一名居民的成本。
保证所有测试用例中 n 的总和不超过 105。
输出格式
For each test case, output a line containing an integer representing the minimum cost to notify all n residents of Khuntien about the announcement.
对于每个测试用例,输出一行,包含一个整数,表示通知坤田镇全部 n 名居民该公告所需的最小花费。
输入输出样例
输入#1
3 6 3 2 3 2 1 1 3 4 3 2 6 3 6 1 100000 100000 1 4 94 1 4 2 3 103 96 86 57
输出#1
16 100000 265
说明/提示
In the first test case, the following is a possible optimal strategy:
- Pak Chanek shares the announcement directly to the 3-rd, 5-th, and 6-th resident. This requires a cost of p+p+p=3+3+3=9.
- The 3-rd resident shares the announcement to the 1-st and 2-nd resident. This requires a cost of b3+b3=2+2=4.
- The 2-nd resident shares the announcement to the 4-th resident. This requires a cost of b2=3.
The total cost is 9+4+3=16. It can be shown that there is no other strategy with a smaller cost.
在第一个测试用例中,以下是一种可能的最优策略:
- Pak Chanek 直接将公告分享给第 3、第 5 和第 6 位居民。这需要花费 p+p+p=3+3+3=9。
- 第 3 位居民将公告分享给第 1 和第 2 位居民。这需要花费 b3+b3=2+2=4。
- 第 2 位居民将公告分享给第 4 位居民。这需要花费 b2=3。
总花费为 9+4+3=16。可以证明,不存在花费更小的其他策略。
输入解题思路,AI测评打分。不知道怎么写?