#K84067. Maximum Total Platform Length
Maximum Total Platform Length
Maximum Total Platform Length
You are given T test cases. In each test case, there are N buildings with their respective heights. After sorting the heights, the maximum total platform length that can be installed is defined as the sum of the differences between each pair of consecutive buildings. In other words, if the sorted heights are \(h_1 \le h_2 \le \cdots \le h_N\), then the answer is:
\(\sum_{i=2}^{N} (h_i - h_{i-1}) = h_N - h_1\)
This ensures that no two platforms overlap. Your task is to compute and output this maximum total platform length for each test case.
inputFormat
The input is given from stdin and follows the format below:
- The first line contains an integer T representing the number of test cases.
- For each test case, the first line contains an integer N.
- The next line contains N space-separated integers representing the heights of the buildings.
outputFormat
For each test case, output the maximum total platform length on a new line to stdout.
## sample3
5
1 3 2 6 4
3
1 2 3
4
8 6 4 2
5
2
6
</p>