Golden Tickets

시간 제한1초메모리 제한2048 MB

요약
N개 팀의 순위가 주어질 때 상위 M위 밖 기관 중 기관별 한 팀씩 최대 K개 팀을 골라 황금 티켓 수여 팀을 순위대로 출력한다.
난이도

쉬움10점 중 3점

유형
해시맵, 그리디, 구현
정답자
아직 제출이 없습니다

문제

There are NN teams participating in INC 2023. The team ranked in the iith position is team S_iS\_i, representing institution T_iT\_i. It is known that the top MM teams in INC 2023 are eligible to participate in The ICPC Asia Jakarta 2023.

Apart from the top MM teams, Golden Tickets are given to at most top KK teams for which their institutions are not in the top MM of INC 2023. However, only at most one Golden Ticket will be given to each institution, and only the team with the highest rank in INC 2023 from each institution qualifies for the Golden Ticket. These Golden Tickets will allow them to participate in The ICPC Asia Jakarta 2023.

Determine the number of teams that will receive the Golden Tickets. Then, output the name of the teams that receive those Golden Tickets, sorted by the rank of the teams.

입력

The first line consists of three integers NN MM KK (1≤M,K≤N≤1001 ≤ M, K ≤ N ≤ 100).

Each of the next NN lines consists of two string S_iS\_i T_iT\_i (1≤∣S_i∣,∣T_i∣≤101 ≤ |S\_i |, |T\_i | ≤ 10) separated by a whitespace. All strings consist of upper case letters. There are no teams with the same name. Formally, S_i≠S_jS\_i \ne S\_j for 1≤i<j≤N1 ≤ i < j ≤ N.

출력

The first line consists of an integer, representing the number of teams that will receive the Golden Tickets. Denote this number as XX.

Then, output XX lines, each consisting of the name of the teams that receive those Golden Tickets, sorted by their rank. If X=0X = 0, then you do not need to print any names.

힌트

Disclaimer

All team names and institution names in the samples are fictional. Any similarities with actual participants in INC 2023 are purely coincidental.

예제4

  1. 예제 1

    입력
    3 1 2
    ARUA UOGX
    NOIHS UHOLO
    IKUBUF UHOLO
    
    예상 출력
    1
    NOIHS
    
  2. 예제 2

    입력
    3 2 1
    ARUA UOGX
    NOIHS UHOLO
    IKUBUF UHOLO
    
    예상 출력
    0
    
  3. 예제 3

    입력
    5 1 2
    ARUA UOGX
    NOIHS UHOLO
    IKUBUF UHOLO
    ANUZAN UVSH
    LAMLA UNIJI
    
    예상 출력
    2
    NOIHS
    ANUZAN
    
  4. 예제 4

    입력
    9 3 3
    ARUA UOGX
    ANUZAN UVSH
    NOIHS UHOLO
    IKUBUF UHOLO
    LAMLA UNIJI
    IKASAS UNIJI
    ESUOMNORI UVSH
    AIHSUR URIP
    AYNEH UVSH
    
    예상 출력
    2
    LAMLA
    AIHSUR