問題一覧 > 通常問題

No.837 Noel-chan and the Stars 2

レベル : / AI推定難易度 : 1225 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 159
作問者 : dama_math / テスター : tatyam
お気に入りにしたユーザー ProblemId : 2600 / 自分の提出
問題文最終更新日: 2019-03-11 21:13:19
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 215 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。