atcoder#ABC275H. [ABC275Ex] Monster
[ABC275Ex] Monster
Score : points
Problem Statement
There are monsters along a number line. At the coordinate is a monster with a stamina of . Additionally, at the coordinate , there is a permanent shield of a strength . This shield persists even when the monster at the same coordinate has a health of or below.
Takahashi, a magician, can perform the following operation any number of times.
- Choose integers and satisfying .
- Then, consume MP (magic points) to decrease by the stamina of each of the monsters at the coordinates .
When choosing and , it is fine if some of the monsters at the coordinates already have a stamina of or below. Note, however, that the shields at all those coordinates still exist.
Takahashi wants to make the stamina of every monster or below. Find the minimum total MP needed to achieve his objective.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum total MP needed to achieve his objective.
5
4 3 5 1 2
10 40 20 60 50
210
Takahashi can achieve his objective as follows.
- Choose . Consume MP, and the staminas of the monsters are .
- Choose . Consume MP, and the staminas of the monsters are .
- Choose . Consume MP, and the staminas of the monsters are .
- Choose . Consume MP, and the staminas of the monsters are .
- Choose . Consume MP, and the staminas of the monsters are .
- Choose . Consume MP, and the staminas of the monsters are .
Here, he consumes a total of MP, which is the minimum possible.
1
1000000000
1000000000
1000000000000000000
10
522 4575 6426 9445 8772 81 3447 629 3497 7202
7775 4325 3982 4784 8417 2156 1932 5902 5728 8537
77917796