#K63852. Equalization Operations
Equalization Operations
Equalization Operations
You are given an array of ( n ) integers. In one operation, you can increase or decrease any element by 1. Your task is to determine the minimum number of such operations required to make all the elements of the array equal.
A key observation is that the optimal target value is the median of the array. The total number of operations needed can be expressed as:
where \( m \) is the median. An array with a single element requires 0 operations. ## inputFormat The input is read from standard input (stdin). The first line contains an integer \( n \) \((1 \leq n \leq 10^5)\), the number of elements in the array. The second line contains \( n \) space-separated integers \( a_1, a_2, \ldots, a_n \) where \( |a_i| \leq 10^9 \). ## outputFormat Output a single integer to standard output (stdout), representing the minimum number of operations required to make all elements equal.## sample
5
1 2 3 4 5
6
$$