問題一覧 > 通常問題

No.609 Noel-chan and the Stars

レベル : / AI推定難易度 : 450 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 244
作問者 : polylogK / テスター : sei0o
お気に入りにしたユーザー ProblemId : 2000 / 自分の提出
問題文最終更新日: 2026-07-02 21:29:41
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
Advent Calendar Contest 2017 (順位表) の他の問題:

Note

This problem is the problem for day 9 of Advent Calendar Contest Advent Calendar 2017.

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 bring all the points to the same height.
Find the minimum total distance 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(1\le N\le 10^5) $.
The second line contains $N$ integers $ Y_i(-10^9 \le Y_i \le 10^9) $.

Update 12/9 0:47: The constraint has been changed to $N(1\le N\le 10^5) $.

Output

Output the minimum total distance as an integer.

Update 12/9 0:57: The output has been changed to an integer.

Sample

Sample 1
Input
5
5 7 5 7 7
Output
4

Aligning them to height $7$ gives $2+0+2+0+0=4$, which is the minimum.

Sample 2
Input
11
-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 0 1000000000 1000000000 1000000000 1000000000 1000000000
Output
10000000000

The answer may not fit in a 32-bit integer.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。