atcoder#ARC129D. [ARC129D] -1+2-1
[ARC129D] -1+2-1
Score : points
Problem Statement
Given is an integer sequence of length : .
You can repeat the operation below any number of times.
- Choose an integer () and add to , respectively. Here, stands for , and stands for .
Determine whether it is possible to make every element of . If it is possible, find the minimum number of operations needed.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to make every element of , print -1
.
If it is possible to do so, print the minimum number of operations needed.
4
3 0 -1 -2
5
We can achieve the objective in five operations, as follows.
- Do the operation with . Now we have .
- Do the operation with . Now we have .
- Do the operation with . Now we have .
- Do the operation with . Now we have .
- Do the operation with . Now we have .
3
1 0 -2
-1
4
1 -1 1 -1
-1
10
-28 -3 90 -90 77 49 -31 48 -28 -84
962