#K92472. Minimum Operations to Achieve Uniform Parity
Minimum Operations to Achieve Uniform Parity
Minimum Operations to Achieve Uniform Parity
In this problem, you are given an array of n integers and an integer parameter (x) (which is not used in the computation). Your task is to determine the minimum number of operations required to make all the elements of the array have the same parity (i.e. all even or all odd).
In one operation, you may increment or decrement any element of the array by 1. Changing a single number’s parity requires exactly one operation. Therefore, the optimal strategy is to change the parity of the minority of the numbers. Formally, if (E) is the number of even numbers and (O) is the number of odd numbers in the array, the minimum number of operations required is
[
\min(E, O)]
Note: The integer (x) is provided as part of the input but does not affect the result.
inputFormat
The first line of input contains a single integer (T) denoting the number of test cases. Each test case is described as follows:
- The first line contains two space-separated integers (n) and (x) (where (x) is not used in the calculations).
- The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single line containing one integer — the minimum number of operations required such that all elements of the array have the same parity.## sample
3
5 3
1 2 3 4 5
4 1
6 7 8 9
3 2
2 4 6
2
2
0
</p>