CF1738A.Glory Addicts

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The hero is addicted to glory, and is fighting against a monster.

The hero has nn skills. The ii-th skill is of type aia_i (either fire or frost) and has initial damage bib_i.

The hero can perform all of the nn 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,

  1. If a skill of type fire and with initial damage cc is performed immediately after a skill of type fire, then it will deal cc damage;
  2. If a skill of type fire and with initial damage cc is performed immediately after a skill of type frost, then it will deal 2c2c damage;
  3. If a skill of type frost and with initial damage cc is performed immediately after a skill of type fire, then it will deal 2c2c damage;
  4. If a skill of type frost and with initial damage cc is performed immediately after a skill of type frost , then it will deal cc damage.

Your task is to find the maximum damage the hero can deal.

英雄沉溺于荣耀,正与一只怪物战斗。

英雄拥有 nn 个技能。第 ii 个技能的类型为 aia_i(火系或冰系),初始伤害值为 bib_i。

英雄可以以任意顺序施展全部 nn 个技能(每个技能恰好施展一次)。每次施展一个技能时,英雄可施放如下魔法:

  • 若当前技能紧接在另一个不同类型的技能之后施展,则其伤害值翻倍。

换言之:

  1. 若一个火系技能(初始伤害为 cc)紧接在另一个火系技能之后施展,则造成 cc 点伤害;
  2. 若一个火系技能(初始伤害为 cc)紧接在另一个冰系技能之后施展,则造成 2c2c 点伤害;
  3. 若一个冰系技能(初始伤害为 cc)紧接在另一个火系技能之后施展,则造成 2c2c 点伤害;
  4. 若一个冰系技能(初始伤害为 cc)紧接在另一个冰系技能之后施展,则造成 cc 点伤害。

你的任务是求出英雄所能造成的最大总伤害值。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1051 \leq t \leq 10^5) — 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 nn (1≤n≤1051 \leq n \leq 10^5), indicating the number of skills.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤10 \leq a_i \leq 1), where aia_i indicates the type of the ii-th skill. Specifically, the ii-th skill is of type fire if ai=0a_i = 0, and of type frost if ai=1a_i = 1.

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤bi≤1091 \leq b_i \leq 10^9), where bib_i indicates the initial damage of the ii-th skill.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5),表示测试用例的数量。接下来的若干行描述每个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示技能的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤10 \leq a_i \leq 1),其中 aia_i 表示第 ii 个技能的类型:若 ai=0a_i = 0,则该技能为火焰系;若 ai=1a_i = 1,则该技能为寒冰系。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤1091 \leq b_i \leq 10^9),其中 bib_i 表示第 ii 个技能的初始伤害值。

保证所有测试用例中 nn 的总和不超过 10510^5。

输出格式

For each test case, output the maximum damage the hero can deal.

对于每个测试用例,输出英雄所能造成的最大伤害。

输入输出样例

  • 输入#1

    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

    输出#1

    2112
    63
    3000000000
    1

说明/提示

In the first test case, we can order the skills by [3,1,4,2][3, 1, 4, 2], and the total damage is 100+2×1+2×1000+10=2112100 + 2 \times 1 + 2 \times 1000 + 10 = 2112.

In the second test case, we can order the skills by [1,4,2,5,3,6][1, 4, 2, 5, 3, 6], and the total damage is 3+2×6+2×4+2×7+2×5+2×8=633 + 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 [1,2,3][1, 2, 3], and the total damage is 1000000000+1000000000+1000000000=30000000001000000000 + 1000000000 + 1000000000 = 3000000000.

In the fourth test case, there is only one skill with initial damage 11, so the total damage is 11.

在第一个测试用例中,我们可以将技能按 [3,1,4,2][3, 1, 4, 2] 的顺序排列,总伤害为 100+2×1+2×1000+10=2112100 + 2 \times 1 + 2 \times 1000 + 10 = 2112。

在第二个测试用例中,我们可以将技能按 [1,4,2,5,3,6][1, 4, 2, 5, 3, 6] 的顺序排列,总伤害为 3+2×6+2×4+2×7+2×5+2×8=633 + 2 \times 6 + 2 \times 4 + 2 \times 7 + 2 \times 5 + 2 \times 8 = 63。

在第三个测试用例中,我们可以将技能按 [1,2,3][1, 2, 3] 的顺序排列,总伤害为 1000000000+1000000000+1000000000=30000000001000000000 + 1000000000 + 1000000000 = 3000000000。

在第四个测试用例中,仅有一个初始伤害为 11 的技能,因此总伤害为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页