#K67857. Equalizing Array Elements
Equalizing Array Elements
Equalizing Array Elements
You are given an array of integers. In one operation, you can either increase or decrease an element by 1. The goal is to make all elements equal with a minimum number of such operations.
The optimal solution is to adjust every element to the median of the array. Mathematically, if you denote the array as \(a_1, a_2, \dots, a_n\) and choose the median value \(m\), then the minimum number of operations required is:
\(\sum_{i=1}^{n} |a_i - m|\)
This problem tests your understanding of median properties and absolute deviation minimization.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\), representing the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output to standard output (stdout) a single integer representing the minimum number of operations required to make all array elements equal.
## sample3
1 2 3
2