4467: A. Glory Addicts
内存限制:512 MB
时间限制:2 S
标准输入输出
题目类型:传统
评测方式:Special Judge
上传者:
提交:60
通过:16
题目描述
The hero is addicted to glory, and is fighting against a monster.
The hero has n skills. The i-th skill is of type ai (either fire or frost) and has initial damage bi.
The hero can perform all of the n skills in any order (with each skill performed exactly once). When performing each skill, the hero can play a magic as follows:
The hero has n skills. The i-th skill is of type ai (either fire or frost) and has initial damage bi.
The hero can perform all of the n 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.
- If a skill of type fire and with initial damage c is performed immediately after a skill of type fire, then it will deal c damage;
- If a skill of type fire and with initial damage c is performed immediately after a skill of type frost, then it will deal 2c damage;
- If a skill of type frost and with initial damage c is performed immediately after a skill of type fire, then it will deal 2c damage;
- If a skill of type frost and with initial damage c is performed immediately after a skill of type frost , then it will deal c damage.
输入格式
Each test contains multiple test cases. The first line contains an integer t (1 <= t <= 105) — 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 n (1 <= n <= 105), indicating the number of skills.
The second line of each test case contains n integers a1, a2, ..., an (0 <= ai <= 1), where ai indicates the type of the i-th skill. Specifically, the i-th skill is of type fire if ai = 0, and of type frost if ai = 1.
The third line of each test case contains n integers b1, b2, ..., bn (1 <= bi <= 109), where bi indicates the initial damage of the i-th skill.
It is guaranteed that the sum of n over all test cases does not exceed 105.
The first line of each test case contains an integer n (1 <= n <= 105), indicating the number of skills.
The second line of each test case contains n integers a1, a2, ..., an (0 <= ai <= 1), where ai indicates the type of the i-th skill. Specifically, the i-th skill is of type fire if ai = 0, and of type frost if ai = 1.
The third line of each test case contains n integers b1, b2, ..., bn (1 <= bi <= 109), where bi indicates the initial damage of the i-th skill.
It is guaranteed that the sum of n over all test cases does not exceed 105.
输出格式
For each test case, output the maximum damage the hero can deal.
输入样例 复制
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
数据范围与提示
In the first test case, we can order the skills by [3, 1, 4, 2], and the total damage is 100 + 2 × 1 + 2 × 1000 + 10 = 2112.
In the second test case, we can order the skills by [1, 4, 2, 5, 3, 6], and the total damage is 3 + 2 × 6 + 2 × 4 + 2 × 7 + 2 × 5 + 2 × 8 = 63.
In the third test case, we can order the skills by [1, 2, 3], and the total damage is 1000000000 + 1000000000 + 1000000000 = 3000000000.
In the fourth test case, there is only one skill with initial damage 1, so the total damage is 1.
In the second test case, we can order the skills by [1, 4, 2, 5, 3, 6], and the total damage is 3 + 2 × 6 + 2 × 4 + 2 × 7 + 2 × 5 + 2 × 8 = 63.
In the third test case, we can order the skills by [1, 2, 3], and the total damage is 1000000000 + 1000000000 + 1000000000 = 3000000000.
In the fourth test case, there is only one skill with initial damage 1, so the total damage is 1.