444. Minimum Moves to Equal Elements II
MediumMedian
In one move you add or subtract 1 from one element. Print the minimum number of moves to make all elements equal.
Input format
Line 1: n Line 2: n integers
Output format
The minimum moves.
Example 1
Input
3 1 2 3
Output
2
Example 2
Input
4 1 10 2 9
Output
16
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…