#K34462. Minimize Absolute Differences
Minimize Absolute Differences
Minimize Absolute Differences
Given an array of integers, reorder the array so that the sum of the absolute differences between consecutive elements is minimized. It can be proven that the optimal sequence is achieved by sorting the array in non-decreasing order. Implement this approach.
Note: Consider that reordering by simply sorting the array minimizes the sum of absolute differences between adjacent values.
inputFormat
The input is read from standard input (stdin) and consists of:
- A single integer n (1 ≤ n ≤ 105), representing the number of elements in the array.
- A line with n space-separated integers.
outputFormat
Output the reordered array as n space-separated integers on a single line to standard output (stdout).
## sample5
4 2 1 3 5
1 2 3 4 5
</p>