問題一覧 > 通常問題

No.838 Noel-chan and the Stars 3

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 164
作問者 : dama_math / テスター : tatyam
お気に入りにしたユーザー ProblemId : 2601 / 自分の提出
問題文最終更新日: 2019-06-10 17:05:02
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. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。