An expedition keeps two ledgers. The first lists every registered climber: a unique climber ID together with a first and last name. The second records base-camp assignments: a climber ID together with the base camp's name and region. Not every climber has been assigned a base camp, and any climber ID that does appear in the assignment ledger appears there at most once.
Produce one merged roster line for every climber in the first ledger, ordered by increasing climber ID: print their first name, last name, and -- if a matching assignment exists -- the camp name and region; if no assignment exists for that climber, print the single character '-' in place of both the camp name and the region.
Line 1: an integer N, the number of climbers.
Next N lines: each contains climberId firstName lastName, where climberId is a positive integer and firstName/lastName are non-empty strings of letters with no spaces. All N climber IDs are distinct.
Next line: an integer M, the number of base-camp assignments.
Next M lines: each contains climberId campName region, where campName and region are non-empty strings of letters/digits with no spaces. Every climberId appearing in this section also appears in the climber ledger above, and no climberId appears more than once in this section.
Print exactly N lines. The line for the climber with the k-th smallest climberId has the form:
firstName lastName campName region
where campName and region are each replaced by "-" if that climber has no base-camp assignment.
1 <= N <= 2000 0 <= M <= N 1 <= climberId <= 10^9 All name/camp/region strings have length 1 to 20 and contain only letters and/or digits.
Example 1
Input
3 1 Asha Rao 2 Ben Kim 3 Chen Liu 2 1 Everbase North 3 Frostpoint South
Expected
Asha Rao Everbase North Ben Kim - - Chen Liu Frostpoint South
Explanation
Climbers 1, 2, 3 are already in ascending order. Climber 1 has an assignment (Everbase, North); climber 2 has none, so both fields are "-"; climber 3 has an assignment (Frostpoint, South).
Example 2
Input
2 5 Dev Shah 2 Eli Wong 0
Expected
Eli Wong - - Dev Shah - -
Explanation
There are no assignments at all (M=0). Sorted by climberId ascending, climber 2 (Eli Wong) comes before climber 5 (Dev Shah), and both get "-" "-" for camp and region.
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 →