The Wayfarer's Guild keeps two separate ledgers each season: a roster listing every member by an id and a call-sign, and a stipend ledger recording the coin payout some (not necessarily all) members received. Every id that appears in the stipend ledger also appears in the roster, and no id is ever repeated within either ledger.
The guild treasurer needs to flag every member whose stipend fell under 1000 coins this season -- including members whose id never appears in the stipend ledger at all, since they received nothing. Print the flagged call-signs in the order those members first appear in the roster.
The first line contains two integers n and m -- the number of roster entries and the number of stipend entries.
Each of the next n lines contains an integer id and a string callSign, describing one roster entry: id callSign.
Each of the next m lines contains an integer id and an integer stipend, describing one stipend entry: id stipend.
Print the call-sign of every roster member whose stipend is below 1000 or missing from the stipend ledger entirely, one per line, in the order those members appear in the roster. If no member qualifies, print nothing.
Example 1
Input
4 2 1 Aria 2 Bex 3 Coen 4 Dara 1 1500 3 800
Expected
Bex Coen Dara
Explanation
The roster has four members in order Aria, Bex, Coen, Dara. Aria's stipend (1500) is at or above 1000, so she is not flagged. Bex and Dara never appear in the stipend ledger at all, so they are flagged. Coen's stipend (800) is below 1000, so he is flagged too. Printed in roster order: Bex, Coen, Dara.
Example 2
Input
3 3 1 Uma 2 Vik 3 Wren 1 2000 2 999 3 1000
Expected
Vik
Explanation
Every member has a recorded stipend. Uma's is 2000 (not flagged). Vik's is 999, strictly below 1000, so Vik is flagged. Wren's is exactly 1000, which does not satisfy 'below 1000', so Wren is not flagged. Only Vik 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 →