#K12761. Optimal Student Rearrangement
Optimal Student Rearrangement
Optimal Student Rearrangement
You are given the heights of N students. Your task is to rearrange the students so that the sum of the absolute differences between heights of students in corresponding positions (when placed in two rows) is minimized.
After analysis, you will notice that arranging the students in non-decreasing order minimizes this sum. In other words, given a list of heights, you should output the list sorted in ascending order.
Mathematically, if the original heights are \(h_1, h_2, \dots, h_N\), then the optimal arrangement is achieved when \(h_1 \le h_2 \le \dots \le h_N\).
inputFormat
The first line of input contains an integer (N) representing the number of students. The second line contains (N) space-separated integers representing the heights of the students.
outputFormat
Output a single line containing the (N) sorted heights in ascending order, separated by a space.## sample
4
10 1 3 5
1 3 5 10