Boss 战AI (CI翻译)
You are fighting a boss with an unknown amount of health. You have a sequence of $n$ spell cards, where the $i$-th card deals $a_i$ damage. You can rearrange your hand and play the cards in any order you choose.
你正在与一个生命值未知的 Boss 战斗。你有一系列包含 $n$ 张法术卡牌,其中第 $i$ 张卡牌会造成 $a_i$ 点伤害。你可以重新排列手中的卡牌,并以任意顺序打出它们。AI (CI翻译)
The boss has an adaptive shield. If you ever play two cards in a row that deal the exact same amount of damage, the shield permanently activates. The card that triggers the shield still deals its normal damage, but all subsequent cards you play will deal $0$ damage.
Boss 拥有自适应护盾。如果你曾经连续打出两张造成完全相同伤害的卡牌,护盾就会永久激活。触发护盾的卡牌仍会造成正常伤害,但你之后打出的所有卡牌都将造成 $0$ 点伤害。AI (CI翻译)
Find the maximum total health the boss can have such that you will defeat him if you arrange and play your cards optimally.
求 Boss 能拥有的最大生命值,使得你以最优方式安排并打出卡牌时一定能够将其击败。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例数量 $t$ ($1 \le t \le 100$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case contains a single integer $n$ ($1 \le n \le 50$) — the number of spell cards.
每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 50$)——法术卡牌的数量。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$) — the damage dealt by each card.
每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$)——每张卡牌造成的伤害。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output a single integer — the maximum total health the boss can have such that you will defeat him.
对于每个测试用例,输出一个整数——在你能够击败 Boss 的前提下,Boss 能拥有的最大生命值。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, you have only $1$ card. You play it, dealing $100$ damage.
在第一个测试用例中,你只有 $1$ 张卡牌。你打出它,造成 $100$ 点伤害。AI (CI翻译)
In the second test case, you can arrange your hand as $[10, 5, 10, 10]$. You play the first 10. Then you play the 5. Then you play the second 10. Then you play the final 10. Because you played two 10s in a row, the shield activates. However, the card that triggers the shield still deals its normal damage. The total damage dealt is $10 + 5 + 10 + 10 = 35$.
在第二个测试用例中,你可以将手中的卡牌排列为 [10, 5, 10, 10]。你先打出第一个 10,然后打出 5,接着打出第二个 10,最后打出最后一个 10。由于你连续打出了两张 10,护盾被激活。然而,触发护盾的卡牌仍会造成正常伤害。因此造成的总伤害为 $10 + 5 + 10 + 10 = 35$。AI (CI翻译)
In the third test case, all cards are distinct. You can simply play them in any order to deal the sum of their damage: $1 + 2 + 3 + 4 + 5 = 15$.
在第三个测试用例中,所有卡牌都各不相同。你可以按任意顺序打出它们,从而造成伤害总和:$1 + 2 + 3 + 4 + 5 = 15$。AI (CI翻译)
In the fourth test case, all $6$ cards deal exactly 7 damage. No matter what order you play them in, your second card will be identical to your first. The second card will trigger the shield and deal its normal damage, but the remaining $4$ cards will deal $0$ damage. The total damage dealt is $7 + 7 = 14$.
在第四个测试用例中,全部 $6$ 张卡牌造成的伤害都恰好为 7。无论你以何种顺序打出卡牌,第二张卡牌都会与第一张相同。第二张卡牌会触发护盾并造成正常伤害,但剩余的 $4$ 张卡牌将造成 $0$ 点伤害。因此造成的总伤害为 $7 + 7 = 14$。AI (CI翻译)
样例
4
1
100
4
10 5 10 10
5
1 2 3 4 5
6
7 7 7 7 7 7
100
35
15
14
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。