#P17502. [ICPC 2026 Wuhan I] The Best Card
[ICPC 2026 Wuhan I] The Best Card
Problem Description
Snakebite is the most powerful card in the game Slay the Spire 2, and Yuki enjoys using it to defeat enemies.
The game lasts for turns. At the start of the game, the enemy has layers of poison.
Yuki has snakebite cards in total. The effect of the -th snakebite is: when played, it increases the enemy's poison layers by . Yuki will play the -th snakebite at the start of the -th turn.
At the end of each turn, let be the number of poison layers on the enemy:
- If , nothing happens;
- If , the enemy takes damage, and the number of poison layers decreases by , i.e., .
To maximize the total damage dealt to the enemy, Yuki can perform enchantments before the game begins. In each enchantment, Yuki chooses a positive integer and increases the value of by . The same index can be selected multiple times.
You need to determine the maximum damage the enemy can receive after Yuki performs enchantments.
Input Format
Each test contains multiple test cases.
The first line contains an integer (), representing the number of test cases.
For each test case:
- The first line contains two integers (, ).
- The second line contains integers (, ).
- The third line contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output a single line containing an integer representing the maximum damage the enemy can receive after Yuki performs enchantments.
5
2 1
2 3
1 4
2 2
3 4
1 3
4 1
3 3 1 4
4 4 1 5
3 0
16 27 62
9 88 11
3 5
9 3 1
8 3 3
13
37
63
3335
126