#K88412. Allocate Students to Sports
Allocate Students to Sports
Allocate Students to Sports
You are given n students and m sports. Each student has a list of m preferences, which is a permutation of the integers from 1 to m, representing the sports in order of priority. The students are numbered from 1 to n.
Your task is to assign each student to exactly one sport. Each student will be assigned to the sport corresponding to his/her highest preference. Formally, let \(n\) be the number of students and \(m\) be the number of sports. For each student \(i\) (\(1 \le i \le n\)), given a preference list \(p_{i,1}, p_{i,2}, \dots, p_{i,m}\), assign student \(i\) to sport \(p_{i,1}\). (Since each sport can accept up to \(n\) students, there is no capacity constraint.)
After allocation, for each sport, output the list of student roll numbers assigned to that sport in increasing order. If no student is assigned to a sport, output an empty line for that sport.
inputFormat
The input is given from standard input in the following format:
- The first line contains two integers \(n\) and \(m\) separated by a space.
- The next \(n\) lines each contain \(m\) space-separated integers. The \(i\)-th of these lines represents the preference list of the \(i\)-th student.
For example:
3 3 1 3 2 2 1 3 3 1 2
outputFormat
Output exactly \(m\) lines. The \(i\)-th line should list the roll numbers of the students allocated to sport \(i\) in increasing order, separated by a space. If no student is allocated to a sport, output an empty line.
For the sample input above, the output should be:
1 2 3## sample
3 3
1 3 2
2 1 3
3 1 2
1
2
3
</p>