A livestreaming platform keeps a roster of streamer accounts and a log of which calendar days each streamer went live at least once (a streamer may go live more than once on the same day, which counts only once toward that day).
A streamer earns Marathon status if there is a run of 5 or more consecutive calendar day numbers on which the streamer went live every single day.
Given the roster and the log, report every Marathon streamer.
The first line contains an integer M, the number of streamers on the roster. Each of the next M lines contains a distinct streamer id (integer) and a name (a token of 1 to 20 letters), separated by a single space. The next line contains an integer K, the number of log entries. Each of the next K lines contains a streamer id and a day number (integer), separated by a single space, meaning that streamer went live at least once on that day. The same (id, day) pair may appear more than once, and log entries are not necessarily given in any particular order.
Print one line "id name" for every Marathon streamer, in increasing order of id. Print nothing if no streamer qualifies.
1 <= M <= 1000 1 <= id <= 100000, and all ids on the roster are distinct 1 <= length of name <= 20 (letters only, a-z and A-Z) 0 <= K <= 20000 1 <= day number <= 1000000000 Every id that appears in a log entry also appears on the roster.
Example 1
Input
2 1 Alice 2 Bob 10 1 1 1 2 1 3 1 4 1 5 2 1 2 3 2 5 2 7 2 9
Expected
1 Alice
Explanation
Alice went live on days 1-5, a run of exactly 5 consecutive days, so she is a Marathon streamer. Bob's days (1, 3, 5, 7, 9) never have two consecutive days, so he does not qualify.
Example 2
Input
3 1 Uma 2 Vik 3 Wex 16 1 5 1 6 1 6 1 8 1 9 1 10 1 11 1 12 2 100 2 101 2 102 2 103 3 1 3 2 3 3 3 4
Expected
1 Uma
Explanation
Uma's distinct days are 5, 6, 8, 9, 10, 11, 12 (the duplicate entry for day 6 is ignored); the run 8-12 is 5 consecutive days, so she qualifies. Vik's days 100-103 form a run of only 4, and Wex's days 1-4 also form a run of only 4, so neither qualifies.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →