欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1876A.Helmets in Night Light
Helmets in Night Light
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 residents in Khuntien.
First, Pak Chanek shares the announcement directly to one or more residents with a cost of 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 , if the -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 other residents with a cost of 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 residents of Khuntien about the announcement?
Input
Each test contains multiple test cases. The first line contains an integer () — the number of test cases. The following lines contain the description of each test case.
The first line contains two integers and (; ) — the number of residents and the cost for Pak Chanek to share the announcement directly to one resident.
The second line contains integers () — the maximum number of residents that each resident can share the announcement to.
The third line contains integers () — the cost for each resident to share the announcement to one other resident.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a line containing an integer representing the minimum cost to notify all residents of Khuntien about the announcement.
Note
In the first test case, the following is a possible optimal strategy:
- Pak Chanek shares the announcement directly to the -rd, -th, and -th resident. This requires a cost of .
- The -rd resident shares the announcement to the -st and -nd resident. This requires a cost of .
- The -nd resident shares the announcement to the -th resident. This requires a cost of .
The total cost is . It can be shown that there is no other strategy with a smaller cost.
Samples
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
16
100000
265
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |