欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1738A.Glory Addicts
Glory Addicts
The hero is addicted to glory, and is fighting against a monster.
The hero has skills. The -th skill is of type (either fire or frost) and has initial damage .
The hero can perform all of the skills in any order (with each skill performed exactly once). When performing each skill, the hero can play a magic as follows:
- If the current skill immediately follows another skill of a different type, then its damage is doubled.
In other words,
- If a skill of type fire and with initial damage is performed immediately after a skill of type fire, then it will deal damage;
- If a skill of type fire and with initial damage is performed immediately after a skill of type frost, then it will deal damage;
- If a skill of type frost and with initial damage is performed immediately after a skill of type fire, then it will deal damage;
- If a skill of type frost and with initial damage is performed immediately after a skill of type frost , then it will deal damage.
Your task is to find the maximum damage the hero can deal.
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 of each test case contains an integer (), indicating the number of skills.
The second line of each test case contains integers (), where indicates the type of the -th skill. Specifically, the -th skill is of type fire if , and of type frost if .
The third line of each test case contains integers (), where indicates the initial damage of the -th skill.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the maximum damage the hero can deal.
Note
In the first test case, we can order the skills by , and the total damage is .
In the second test case, we can order the skills by , and the total damage is $3 + 2 \times 6 + 2 \times 4 + 2 \times 7 + 2 \times 5 + 2 \times 8 = 63$.
In the third test case, we can order the skills by , and the total damage is .
In the fourth test case, there is only one skill with initial damage , so the total damage is .
Samples
4
4
0 1 1 1
1 10 100 1000
6
0 0 0 1 1 1
3 4 5 6 7 8
3
1 1 1
1000000000 1000000000 1000000000
1
1
1
2112
63
3000000000
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |