#K14361. Maximizing Absolute Differences in a Sequence
Maximizing Absolute Differences in a Sequence
Maximizing Absolute Differences in a Sequence
Given a sequence of n integers, rearrange the sequence so that the sum of absolute differences between consecutive elements is maximized. The sum is calculated as
\( S = \sum_{i=1}^{n-1} |a_i - a_{i-1}| \).
Your task is to output one valid rearrangement of the given sequence that achieves this goal. If there are multiple valid solutions, any one of them will be accepted.
inputFormat
The first line contains an integer n, representing the number of integers in the sequence.
The second line contains n space-separated integers.
outputFormat
Output a single line with the rearranged sequence of integers separated by spaces, such that the sum of the absolute differences between adjacent elements is maximized.
## sample4
1 2 3 4
1 4 2 3