No.837 Noel-chan and the Stars 2
Problem Statement
You are given $N$ points, and the height of point $i$ is $Y_i$. Noel-chan can freely move the heights of the points.
One day, Noel-chan decided she wanted to move the points so that the heights of the points take exactly 2 distinct values.
Find the minimum possible total distance that Noel-chan needs to move the points.
However, Noel-chan can only change the height of each star by an integer distance.
Input
$N$
$Y_1$ $Y_2$ $\cdots$ $Y_{N-1}$ $Y_N$
The first line contains the number of points $N(2\leq N \leq 10^5)$.
The second line contains $N$ integers $Y_i(−10^9\leq Y_i\leq 10^9)$.
Output
Output the minimum total distance as an integer. Print a newline at the end.
Sample
Sample 1
Input
5 1 3 4 6 6
Output
3
If $Y_1,Y_2,Y_3$ are changed to 3 and $Y_4,Y_5$ are changed to 6, the total distance is $2+0+1+0+0=3$, which is the minimum.
Sample 2
Input
3 3 3 4
Output
0
There is no need to move any points.
Sample 3
Input
3 3 3 3
Output
1
Note that the heights of the points must take exactly 2 distinct values.
Since Noel-chan can only change heights by integer distances, 1 is the minimum.
Sample 4
Input
10 -3 14 15 92 65 35 89 79 32 38
Output
116
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
dama_math
tatyam