欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1914C.Quests
Quests
Monocarp is playing a computer game. In order to level up his character, he can complete quests. There are quests in the game, numbered from to .
Monocarp can complete quests according to the following rules:
- the -st quest is always available for completion;
- the -th quest is available for completion if all quests have been completed at least once.
Note that Monocarp can complete the same quest multiple times.
For each completion, the character gets some amount of experience points:
- for the first completion of the -th quest, he gets experience points;
- for each subsequent completion of the -th quest, he gets experience points.
Monocarp is a very busy person, so he has free time to complete no more than quests. Your task is to calculate the maximum possible total experience Monocarp can get if he can complete no more than quests.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers and (; ) — the number of quests and the maximum number of quests Monocarp can complete, respectively.
The second line contains integers ().
The third line contains integers ().
Additional constraint on the input: the sum of over all test cases does not exceed .
Output
For each test case, print a single integer — the maximum possible total experience Monocarp can get if he can complete no more than quests.
Note
In the first test case, one of the possible quest completion sequences is as follows: ; its total experience is equal to $\underline{4} + 1 + \underline{3} + \underline{1} + 1 + \underline{2} + 1 = 13$ (the underlined numbers correspond to the instances when we complete a quest for the first time).
In the second test case, one of the possible quest completion sequences is as follows: ; its total experience is equal to .
In the third test case, one of the possible quest completion sequences is as follows: ; its total experience is equal to $\underline{3} + \underline{2} + 3 + 3 + \underline{4} = 15$.
Samples
4
4 7
4 3 1 2
1 1 1 1
3 2
1 2 5
3 1 8
5 5
3 2 4 1 4
2 3 1 4 7
6 4
1 4 5 4 5 10
1 5 1 2 5 1
13
4
15
15
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |