Contest Advancement
면접 대비시간 제한2초메모리 제한2048 MB
학교별 상한 c를 지키면서 상위 k개 팀을 선발하되 정원이 차지 않으면 남은 자리는 순위대로 채우는 문제이다.
문제
You are the RCD for your regional contest. It just ended and you now need to decide which teams qualify for the next level of competition. The teams are uniquely ranked (there are no ties). The next level has a limit on how many teams from any given school can participate. However, if that limit causes there to be not enough teams advancing, the remaining slots will be filled by teams from schools over the limit. If this happens, you will always give preference to higher-ranking teams, even if it means many teams from the same school advancing.
Output, in rank order, the teams that qualify for the next contest.
입력
The first line of input contains three integers , () and (), where is the number of teams in the competition, is the number of teams that will advance, and is the limit on the number of teams that may advance from any given school.
Each of the next lines contains two integers and (). Each line describes a team, with being the team's unique ID, and indicating the team's school. All team IDs will be distinct. The teams will be listed in rank order, with the highest ranking teams first.
출력
Output lines. On each line output a single integer, which is the ID of a team. List the IDs of the teams that qualified to advance in rank order.