P27862 [洛谷] [NICA #2] Rain of Retrospection
普及
题目描述

Problem Description

Little Ran has two positive integers \( x \) and \( y \). She also has two sequences of positive integers \( a \) and \( c \) of length \( n \) such that \( a_i x + y = c_i \) for \( 1 \leq i \leq n \).

Unfortunately, she has forgotten the values of all \( a_i \) and the value of \( y \). She provides you with the value of \( x \) and the sequence \( c \), and hopes that you can reconstruct a set of values for \( y \) and the sequence \( a \) that satisfy the original condition.

Since there may be many such solutions, she wants you to maximize the value of \( y \) and output it (note that you do not need to output the sequence \( a \)). If it is not possible to reconstruct such a set of numbers, please output \(-1\) to indicate no solution.

Input Format

The first line contains two positive integers \( n \) and \( x \), as described in the problem statement.

The second line contains \( n \) positive integers describing the array \( c \), where the \( i \)-th number is \( c_i \).

Output Format

Output a single positive integer, which is the largest value of \( y \) that you can reconstruct. If it is not possible to reconstruct such a positive integer, output \(-1\).

Sample Input and Output

Sample Input #1

5 2
4 6 8 10 12

Sample Output #1

2

Sample Input #2

5 2
3 6 9 12 15

Sample Output #2

-1

Notes

The data guarantees that \( 1 \leq n \leq 10^5 \), \( 1 \leq x \leq 10^{12} \), and \( 1 \leq c_i \leq 10^{18} \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 2 4 6 8 10 12
样例输出
2