#C5811. Maximizing Absolute Differences
Maximizing Absolute Differences
Maximizing Absolute Differences
Given an array of distinct integers, your task is to reorder the array so that the sum of the absolute differences between consecutive elements is maximized. In other words, for a sequence \(a_1, a_2, \dots, a_n\), you want to maximize the sum:
\(\displaystyle S = \sum_{i=1}^{n-1} |a_{i+1} - a_i|\)
You will be given multiple test cases. For each test case, output one valid reordering of the array that achieves this objective. If there are multiple valid answers, output any one of them.
inputFormat
The input consists of several test cases:
- The first line contains an integer \(T\), the number of test cases.
- For each test case, the first line contains an integer \(n\) (the number of integers).
- The next line contains \(n\) space-separated distinct integers.
outputFormat
For each test case, output a single line containing the reordered sequence of integers that maximizes the sum of absolute differences between consecutive elements. Each integer should be separated by a single space.
## sample2
5
1 5 3 2 4
3
-1 0 1
5 1 4 2 3
1 -1 0
</p>