#C3375. Equalizing Integer Array
Equalizing Integer Array
Equalizing Integer Array
You are given a list of N positive integers. In one operation, you can increment or decrement any integer in the list by 1. Your task is to find the minimum number of operations required to make all the integers in the list equal.
The optimal strategy is to make all elements equal to the median of the list. Recall that the operation count needed is given by \[ \text{Operations} = \sum_{i=1}^{N} |a_i - m|, \] where \(m\) is the median of the list.
Note: For an even-length list, any number between the two middle values minimizes the total number of operations. For simplicity, you may use the upper median (i.e. element at index \(\lfloor N/2 \rfloor\) after sorting).
inputFormat
The input is given from the standard input (stdin) and consists of two lines:
- The first line contains a single integer N, the number of elements in the array.
- The second line contains N space-separated positive integers.
outputFormat
Output a single integer representing the minimum number of operations required to make all the integers in the list equal. Write the result to the standard output (stdout).
## sample1
1000
0