#abc368c. C - Triple Attack
C - Triple Attack
Score : points
问题陈述
你正在玩一个游戏。
有 个敌人排成一行,第 个敌人从前面开始的生命值为 。
你将重复以下动作,直到所有敌人的生命值都变成 或更少,使用一个变量 ,初始值为 。
- 将 增加 。然后,攻击最前面的敌人,如果其生命值大于或等于 。如果 是 的倍数,敌人的生命值减少 ;否则,减少 。
找出当所有敌人的生命值都变成 或更少时, 的值。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are playing a game.
There are enemies lined up in a row, and the -th enemy from the front has a health of .
You will repeat the following action until the healths of all enemies become or less, using a variable initialized to .
- Increase by . Then, attack the frontmost enemy with health or more. If is a multiple of , the enemy's health decreases by ; otherwise, it decreases by .
Find the value of when the healths of all enemies become or less.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
6 2 2
Sample Output 1
8
The actions are performed as follows:
- becomes . Attack the 1st enemy, and its health becomes .
- becomes . Attack the 1st enemy, and its health becomes .
- becomes . Attack the 1st enemy, and its health becomes .
- becomes . Attack the 1st enemy, and its health becomes .
- becomes . Attack the 2nd enemy, and its health becomes .
- becomes . Attack the 2nd enemy, and its health becomes .
- becomes . Attack the 3rd enemy, and its health becomes .
- becomes . Attack the 3rd enemy, and its health becomes .
Sample Input 2
9
1 12 123 1234 12345 123456 1234567 12345678 123456789
Sample Output 2
82304529
Sample Input 3
5
1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 3
3000000000
Beware of integer overflow.