#K44542. Minimum Operations to Equalize Array Elements
Minimum Operations to Equalize Array Elements
Minimum Operations to Equalize Array Elements
In this problem, you are given an array of integers. Your task is to determine the minimum total number of operations needed to make all the elements equal. In one operation, you can increment or decrement an element by 1. It can be shown that the optimal strategy is to change all elements to the median value of the array. Mathematically, if (a_1, a_2, \ldots, a_n) is the array and (m) is the median, the answer is (\sum_{i=1}^{n} |a_i - m|).
inputFormat
The first line of the input contains a single integer (n) ( (1 \leq n \leq 10^5)) representing the number of elements. The second line contains (n) space-separated integers denoting the array elements.
outputFormat
Output a single integer which is the minimum number of operations required to make all elements equal.## sample
1
5
0
</p>