#K92382. Divide Students into Groups
Divide Students into Groups
Divide Students into Groups
You are given the scores of n students along with their sequential IDs (starting from 1). Your task is to compute the median score and to divide the students into two groups.
Group A contains students whose scores are less than or equal to the median, while Group B contains students whose scores are greater than the median.
For an odd number of students, the median is the middle score after sorting all scores in non-decreasing order. For an even number of students, if the two middle scores are \(a\) and \(b\) (with \(a \le b\)), then the median is defined as \(\frac{a+b}{2}\).
The final output must display the median on the first line, followed by a line listing the student IDs and their corresponding scores in Group A (in increasing order of their original IDs) and then a line listing the student IDs and scores in Group B (also sorted by increasing student IDs). If a group is empty, output an empty line.
inputFormat
The first line of input contains a single integer n, the number of students.
The second line contains n space-separated integers, where each integer represents the score of a student in the order of their IDs (starting at 1).
outputFormat
Output three lines:
- The first line contains the median score (if the result is a whole number, it should be printed without a decimal point).
- The second line lists the student IDs and scores (space-separated) for Group A, in increasing order of student IDs.
- The third line lists the student IDs and scores (space-separated) for Group B, in increasing order of student IDs.
If a group is empty, print an empty line for that group.
## sample6
600 720 1050 800 950 1000
875
1 600 2 720 4 800
3 1050 5 950 6 1000
</p>