#K90807. Arrange the Students
Arrange the Students
Arrange the Students
Given an array of integers where each element represents the height of a student, you are required to rearrange the array such that all present students (with height values not equal to -1) are sorted in non-decreasing order, while the absent students (denoted by -1) remain in their original positions.
In other words, if we denote the input array as (a_1, a_2, \dots, a_n) and its output as (b_1, b_2, \dots, b_n), then for every index (i) where (a_i \neq -1), the element (b_i) should be the corresponding element from the sorted order of all (a_j)'s that are not equal to -1, preserving the locations of all (-1) entries.
inputFormat
Input is given from standard input (stdin) and consists of two lines. The first line contains an integer (N) representing the number of students. The second line contains (N) space-separated integers representing the heights of the students. The value (-1) indicates an absent student.
outputFormat
Output a single line to standard output (stdout) containing (N) space-separated integers. In the output, the heights of all present students should appear in non-decreasing order while the positions of the absent students ((-1)) remain unchanged.## sample
7
5 -1 3 2 -1 -1 4
2 -1 3 4 -1 -1 5