No.838 Noel-chan and the Stars 3
Problem Statement
You are given $N$ points. The height of point $i$ is $Y_i$. Noel-chan can freely move the heights of the points.
One day, Noel-chan wanted to move the points so that they satisfy the following condition:
Condition: For every point, there exists another point whose height is equal to that point's height.
Find the minimum possible total distance that Noel-chan needs to move the points.
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
7 1 2 3 4 5 6 7
Output
4
For example, if $Y_1,Y_2,Y_3$ are moved to 2, $Y_4,Y_5$ to 4, and $Y_6,Y_7$ to 6,
the total distance is $1+0+1+0+1+0+1=4$, which is the minimum.
Sample 2
Input
3 3 3 4
Output
1
Moving $Y_3$ to 3 minimizes the total distance.
Sample 3
Input
10 -3 14 15 92 65 35 89 79 32 38
Output
41
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
dama_math
tatyam