atcoder#ARC142F. [ARC142F] Paired Wizards
[ARC142F] Paired Wizards
Score : points
Problem Statement
Two wizards, and , are fighting with a monster.
Initially, each of the wizards has a magic power of . They know the following two spells.
- Spell : Increases the caster's magic power by .
- Spell : Deals damage equal to the caster's magic power to the monster.
After each wizard uses a spell times, they will withdraw from the battle. For each , they must use one of the following combinations of spells for their -th spells.
- casts Spell , and casts Spell .
- casts Spell , and casts Spell .
Find the maximum total damage that can be dealt to the monster before the withdrawal.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 1 2 2
2 1 2 2
2 1 1 1
3
The maximum total damage can be achieved as follows.
- As the -st spells, use , increasing both 's and 's magic powers to .
- As the -nd spells, use , dealing points of damage in total.
- As the -rd spells, use , dealing point of damage by 's spell and increasing 's magic power to .
5
2 2 2 2
2 2 2 2
2 2 2 2
2 2 2 2
2 2 2 2
0
Casting Spell with a magic power of deals no damage.
8
1 1 2 2
2 2 2 1
1 1 2 1
1 1 2 2
2 1 1 1
1 2 1 2
2 1 1 2
2 1 2 1
20
20
2 1 2 1
2 1 1 1
1 2 1 1
2 2 1 2
2 2 2 1
1 1 2 1
1 2 2 2
2 2 2 1
1 1 1 2
1 2 1 2
1 2 2 2
2 1 1 2
2 1 1 1
1 2 1 2
1 2 1 2
1 1 1 2
1 1 2 1
2 2 1 1
1 2 2 2
2 1 1 2
138