No.609 Noel-chan and the Stars
問題文最終更新日: 2026-07-02 21:29:41
English (AI translation)
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) $.
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もしくは右上の雲マークをクリックしてアカウントを作成してください。
sei0o