#C532. Optimal Arrangement of Programmers
Optimal Arrangement of Programmers
Optimal Arrangement of Programmers
You are given a number of test cases. In each test case, a list of programmers' efficiencies is provided. Your task is to arrange these efficiencies in an optimal order so that the sum of the differences between consecutive efficiencies is minimized. Mathematically, if the arranged efficiencies are \(E_1, E_2, \ldots, E_n\), you are to minimize the sum
\(\sum_{i=1}^{n-1} |E_{i+1}-E_i|\)
A simple observation shows that sorting the list in ascending order yields the optimal result.
inputFormat
The input begins with an integer \(T\) denoting the number of test cases. Each test case is described by two lines:
- The first line contains an integer \(N\) which represents the number of programmers.
- The second line contains \(N\) space-separated integers denoting the programmers' efficiencies.
Input is provided via standard input (stdin).
outputFormat
For each test case, output a single line containing the optimally arranged efficiencies separated by a space. The output should be directed to standard output (stdout).
## sample2
5
4 1 3 2 5
3
10 7 15
1 2 3 4 5
7 10 15
</p>