#K6936. Equalize Building Heights
Equalize Building Heights
Equalize Building Heights
You are given multiple test cases. In each test case, there are N buildings with given heights. Your task is to determine the minimum number of operations required to make the height of all buildings the same.
In one operation, you can increase or decrease the height of any building by 1 unit. The optimal strategy is to adjust all buildings to the median height.
Note: If there are an even number of buildings, you may choose either of the two central numbers as the target height, and the minimized total operations will be the same.
inputFormat
The first line of input contains an integer T, the number of test cases. Then for each test case, the input is as follows:
- The first line contains a single integer N, the number of buildings.
- The second line contains N space-separated integers representing the heights of the buildings.
outputFormat
For each test case, output a single line containing the minimum number of operations required to make all building heights equal.
## sample3
4
1 2 3 4
3
10 10 10
5
3 4 2 5 3
4
0
4
</p>