Who Owns the Prize?
InterviewTime limit4sMemory limit1024 MB
For each of four subjects in order, pick the highest-scoring student who has not yet won a prize, breaking ties by smaller student number.
- Level
Medium4 of 10
- Topics
- Sorting, Implementation, Greedy, Array
- Solved
- No attempts yet
Problem
Hyemin's class has students, and each student is assigned a distinct number. This exam covers four subjects: Korean, English, Math, and Science. To encourage the students to study hard, the class decided to give a prize to the top scorer in each subject. The prizes are awarded in the order Korean, English, Math, Science, and since the class wants as many students as possible to receive a prize, each student can receive a prize only once. For example, if the student who places first in Korean also places first in Math, that student already received a prize for Korean and cannot receive another prize in a different subject. So for Math, the prize goes to the student with the highest score among those who have not yet received a prize. If there is a tie, the student with the smaller number receives the prize. Output the number of the student who receives the prize in each subject.
Input
The first line gives the number of students ().
The next lines, from the second line to the -th line, each give a student's number () followed by their Korean score , English score , Math score , and Science score , in that order, as space-separated integers. Student numbers are distinct. ()
Output
Print the numbers of the students who receive prizes, in the order Korean, English, Math, Science, separated by spaces.