304128: CF793A. Oleg and shares
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Oleg and shares
题意翻译
给你n支股票原价(单位:卢布),每秒钟可能会有任意一支股票的价格下降k卢布,注意,股票的价格可能是负的。 请给出所有股票的价格均变得相同所要经过的最短时间,若不可能请输出“-1”(如样例二所示,不包括引号)。题目描述
Oleg the bank client checks share prices every day. There are $ n $ share prices he is interested in. Today he observed that each second exactly one of these prices decreases by $ k $ rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all $ n $ prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?输入输出格式
输入格式
The first line contains two integers $ n $ and $ k $ ( $ 1<=n<=10^{5},1<=k<=10^{9} $ ) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains $ n $ integers $ a_{1},a_{2},...,a_{n} $ ( $ 1<=a_{i}<=10^{9} $ ) — the initial prices.
输出格式
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
输入输出样例
输入样例 #1
3 3
12 9 15
输出样例 #1
3
输入样例 #2
2 2
10 9
输出样例 #2
-1
输入样例 #3
4 1
1 1000000000 1000000000 1000000000
输出样例 #3
2999999997