Seat Reservation
InterviewTime limit1sMemory limit1024 MB
Replay the seat applications in time order, granting a seat only when it is unreserved, and report each student's final seat by student number.
- Level
Easy3 of 10
- Topics
- Sorting, Simulation
- Solved
- No attempts yet
Problem
Daejeon Science High School has a first-come, first-served system for reserving study seats.
There are students. Each student has a unique student number from to . Each student can apply for one of seats. Each seat has a unique number from to .
The system works as follows.
- Each seat is either reserved or unreserved. Before any student applies, every seat is unreserved.
- If a student applies for a seat that is already reserved, the application is invalid. An application that is not invalid is successful.
- A student whose application succeeds is assigned that seat immediately, and the seat becomes reserved.
- If a student who already has a seat succeeds in applying for another seat, the seat they had before becomes unreserved.
The system failed, so the applications were not processed correctly. Fortunately, the server kept a log of the applications. Each log entry has the time of the application, the seat number the student applied for, and the student number . A smaller means the application happened earlier.
Given the number of students and the log, write a program that finds the seat each student is finally assigned.
Input
The first line contains the number of students , the number of seats , and the number of log entries , separated by spaces.
Each of the next lines contains an application time , the seat number , and the student number , separated by spaces. , ,
All application times are distinct. The log is not necessarily sorted by time.
Output
On each line, print the student number and the seat number that student is finally assigned, in increasing order of student number, separated by a space. Do not print students who did not apply for any seat or who never succeeded in applying for a seat.