#C8739. Minimum Total Effort to Connect Peaks
Minimum Total Effort to Connect Peaks
Minimum Total Effort to Connect Peaks
You are given several test cases. In each test case, there are N peaks with given altitudes. Your task is to connect all the peaks with the minimum total effort.
The effort required to connect two adjacent peaks is the absolute difference between their altitudes. If you sort the altitudes in non-decreasing order as \(a_1, a_2, \dots, a_N\), then the minimum total effort is given by
\(\displaystyle \sum_{i=1}^{N-1} (a_{i+1}-a_i)=a_N-a_1\)
Calculate and output this minimum total effort for each test case.
inputFormat
The first line contains an integer T representing the number of test cases. For each test case, the first line contains an integer N indicating the number of peaks. The second line contains N space-separated integers representing the altitudes of the peaks.
outputFormat
For each test case, output a single integer on a new line, which is the minimum total effort required to connect all the peaks.
## sample2
3
1 3 6
4
6 2 8 4
5
6
</p>