A conference check-in system keeps two records. The first is the attendee roster: every registrant's internal id and display name, listed in the order each person registered. The second is the badge-printing log: for every attendee whose physical badge has already been printed, one line records their internal id together with the badge number engraved on it. Not every attendee has been printed yet, and the log never contains more than one printed-badge line for the same attendee id. For each attendee on the roster, in registration order, report their display name followed by their badge number — or -1 if no badge has been printed for them yet.
n (1 <= n <= 100000) — the number of attendees on the roster.n lines: id name, where id is a distinct integer (1 <= id <= 10^9) and name is a non-empty string of at most 20 characters containing no whitespace.m (0 <= m <= n) — the number of printed-badge log entries.m lines: id badgeNumber, where id matches exactly one of the attendee ids listed above, no id appears in more than one log line, and badgeNumber is a positive integer (1 <= badgeNumber <= 10^9).Print exactly n lines. The i-th line must contain the name of the i-th roster attendee (in the order they appear in the input) followed by a single space and their badge number, or -1 if that attendee has no entry in the printed-badge log.
n roster ids are pairwise distinct.id is guaranteed to belong to some attendee on the roster.Example 1
Input
3 101 Ava 102 Ben 103 Cy 2 102 55 101 30
Expected
Ava 30 Ben 55 Cy -1
Explanation
Ava (id 101) and Ben (id 102) each have a badge-log entry (30 and 55 respectively), while Cy (id 103) has no entry, so Cy's badge number is reported as -1: "Ava 30", "Ben 55", "Cy -1".
Example 2
Input
2 5 Uma 9 Zoe 0
Expected
Uma -1 Zoe -1
Explanation
No badges have been printed yet (the log is empty), so every attendee's badge number is reported as -1: "Uma -1", "Zoe -1".
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 →