Time limit
2s
Memory limit
128 MB
An arithmetic progression is a sequence in which the difference between every two consecutive terms is constant. For example, 3 5 7 9 11 13 is an arithmetic progression with common difference 2. In this problem, the real-valued sequence A is defined as A_i = A_0 + i*d.
You are given a sequence S of length N. For every i with 0 <= i < N, it must satisfy S_i = floor(A_{i+1}), and S is nondecreasing. Here, floor(x) is the greatest integer less than or equal to x. For example, floor(3.4) = 3, floor(0.6) = 0, floor(-1.2) = -2, and floor(-0.6) = -1.
Find the smallest possible value of d satisfying these conditions. The value d must be at least 0.
The first line contains the length N of S and the initial value A_0. The second line contains N integers, from S_0 through S_{N-1}. If N = 0, the second line is not given.
N is an integer between 0 and 50, inclusive. The absolute value of A_0 and of every element of S is at most 10^6.
Print the minimum possible value of d. An absolute or relative error of at most 10^{-9} is accepted. If no such value exists, print -1.