atcoder#AGC024C. [AGC024C] Sequence Growing Easy
[AGC024C] Sequence Growing Easy
Score : points
Problem Statement
There is a sequence of length , where every element is initially . Let denote the -th element of .
You are given a sequence of length . The -th element of is . Determine if we can make equal to by repeating the operation below. If we can, find the minimum number of operations required.
- Choose an integer such that . Replace the value of with the value of plus .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If we can make equal to by repeating the operation, print the minimum number of operations required. If we cannot, print .
4
0
1
1
2
3
We can make equal to as follows:
- Choose . becomes .
- Choose . becomes .
- Choose . becomes .
3
1
2
1
-1
9
0
1
1
0
1
2
2
1
2
8