루미 알고리즘

#1461골드Birthday Memorization

PO 2019 결선코딩출제 Karl Lundstig영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

Krarkl wants to learn the birthdays of all his N friends, so he knows whom to congratulate each day. Unfortunately collisions sometimes arise, meaning several friends may have the same birthday. This may confuse Krarkl, so he decided to only remember the birthday of the friend he likes the most in case of a collision. Given a list of birthdays for each of his friends and how much Krarkl likes each friend, print what friends Krarkl will remember the birthday for.

Input

The first line of input contains an integer N (1 ≤ N ≤ 2000), the number of friends.

Then N lines follow, one for each friend. The i'th of these lines contains a string with the i'th friend's first name S_i (S_i will be between 1 and 10 letters long), an integer C_i (0 ≤ C_i ≤ 100000) denoting how much Krarkl likes the friend, and their birthday given in the format DD/MM (where DD is a day between 01 and 31, and MM is a month between 01 and 12). A higher value of C_i means that Krarkl likes that friend more.

The birthdays will be real dates during 2020 (a leap year), for example 28/02 for February 28. All names will consist only of small English letters (a-z) with a capital first letter (A-Z). All C_i will be distinct.

Output

On the first line, print an integer K – the number of friends whose birthdays Krarkl will remember.

This should be followed by K lines containing a single word each, the first names of the chosen friends, in lexicographical order.

Scoring

Your solution will be tested on a number of test case groups. To get the points for a group, you need to pass all test cases in the group.

GroupPointsConstraints
130N ≤ 100
270No further constraints

Explanation of samples

In the first sample, Sanna and Simon have the same birthday. Since Krarkl likes Sanna less than Simon (1 < 2), Krarkl will only remember Simon's and Saga's birthdays.

In the second sample, Krarkl has really bad luck and will miss half of his friends' birthdays.

예제

예제 1

입력
3
Sanna 1 16/03
Simon 2 16/03
Saga 3 14/10
출력
2
Saga
Simon

예제 2

입력
10
Oden 78 03/12
Tor 132 14/05
Freja 10000 14/05
Loke 512 12/10
Hel 14 04/05
Fjorgynn 532 13/05
Hildegun 500 13/05
Vindsval 17 03/12
Snotra 20 04/05
Kvaser 420 03/12
출력
5
Fjorgynn
Freja
Kvaser
Loke
Snotra

출처 표기

출처: Programmeringsolympiaden 2019년 결선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.