Tokyo2020
InterviewTime limit8sMemory limit1024 MB
Given medal records for each year, find the earliest year with the most golds and the earliest year with the most total medals.
- Level
Easy3 of 10
- Topics
- Implementation, Hash map, Sorting
- Solved
- No attempts yet
Problem
The Japanese team at the 2020 Tokyo Olympics finished every event on August 8, 2021, and won 58 medals in total: 27 gold, 14 silver, and 17 bronze.
Setting that aside, you are given the results of Olympic events, and you must find the year with the most gold medals and the year with the most medals. If several years qualify, find the earliest among them.
Input
The input consists of multiple data sets. Each data set has the following format.
N
Y1 S1 M1
...
YN SN MN
Each data set has N+1 lines. The first line contains the number of medals N (1 ≤ N ≤ 200) won in Olympic events. The following N lines list the results of Olympic events, one per line. Each line contains the year Yi (1896 ≤ Yi ≤ 2021) in which the event was held, the event name Si (1 ≤ |Si| ≤ 20), a string of English letters only, and the medal color Mi (Mi ∈ { "Gold", "Silver", "Bronze" }), in that order. Mi = "Gold" means a gold medal was won, Mi = "Silver" means a silver medal was won, and Mi = "Bronze" means a bronze medal was won. The given event results are guaranteed to contain at least one j (1 ≤ j ≤ N) with Mj = "Gold".
The end of the input is indicated by a line containing a single zero. The number of data sets does not exceed 50.
Output
For each data set, output the earliest year among the years with the most gold medals and the earliest year among the years with the most medals, separated by a single space.