

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
すぬけ君は、長さ の整数列 を持っています。
すぬけ君は、整数 を自由に選びます。 この時、 と が離れているとすぬけ君は悲しいです。 より具体的には、すぬけ君の悲しさの値は、次の式で計算されます。 なおここで、 は の絶対値を返す関数です。
すぬけ君の悲しさの値の最小値を求めてください。
制約
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
出力
すぬけ君の悲しさの値の最小値を出力せよ。
入力例 1Copy
5 2 2 3 5 5
出力例 1Copy
2
とすれば、すぬけ君の悲しさの値は、 となります。 をどのように選んでも、すぬけ君の悲しさの値を 未満にすることは出来ないので、答えは になります。
入力例 2Copy
9 1 2 3 4 5 6 7 8 9
出力例 2Copy
0
入力例 3Copy
6 6 5 4 3 2 1
出力例 3Copy
18
入力例 4Copy
7 1 1 1 1 2 3 4
出力例 4Copy
6
Score : points
Problem Statement
Snuke has an integer sequence of length .
He will freely choose an integer . Here, he will get sad if and are far from each other. More specifically, the sadness of Snuke is calculated as follows:
Here, is a function that returns the absolute value of .
Find the minimum possible sadness of Snuke.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible sadness of Snuke.
Sample Input 1Copy
5 2 2 3 5 5
Sample Output 1Copy
2
If we choose , the sadness of Snuke would be . Any choice of does not make the sadness of Snuke less than , so the answer is .
Sample Input 2Copy
9 1 2 3 4 5 6 7 8 9
Sample Output 2Copy
0
Sample Input 3Copy
6 6 5 4 3 2 1
Sample Output 3Copy
18
Sample Input 4Copy
7 1 1 1 1 2 3 4
Sample Output 4Copy
6