#C8394. Minimize Adjacent Height Difference
Minimize Adjacent Height Difference
Minimize Adjacent Height Difference
You are given a list of integers representing the heights of sculptures. Your task is to rearrange these heights so that the maximum difference between any two adjacent values is minimized. Essentially, you need to sort the numbers in ascending order.
Formally, given a list \( H = [h_1, h_2, \dots, h_n] \), you need to produce a permutation \( H' = [h'_1, h'_2, \dots, h'_n] \) such that the quantity \[ \max_{1 \leq i < n} (h'_{i+1} - h'_i) \] is minimized. It can be easily observed that sorting \( H \) in non-decreasing order achieves this goal.
Input/Output Format Change: Instead of defining a function, your program will read from standard input (stdin) and output to standard output (stdout).
inputFormat
The first line contains an integer \( n \) (\( n \ge 2 \)), the number of sculptures. The second line contains \( n \) space-separated integers representing the heights of the sculptures.
outputFormat
Output the rearranged heights in a single line, separated by spaces, such that the difference between any two adjacent sculptures is minimized.
## sample4
1 10 4 7
1 4 7 10