A neighborhood tool-lending library owns several models of hand tools, each purchased in some fixed total quantity. Whenever a member checks out one unit of a tool, the front desk appends that tool's id to a running checkout log; when a unit is returned, the desk simply deletes that entry, so the log always lists exactly the units presently on loan. Given the library's full inventory and today's checkout log, report every tool model that is currently checked out down to zero -- that is, every unit the library owns of that model is on loan right now, leaving nothing available for a walk-in member.
Line 1: an integer n -- the number of tool models. Each of the next n lines contains two integers id_i and copies_i -- the model's unique identifier and the total number of units the library owns of that model. The next line contains an integer m -- the number of units currently on loan. The next line contains m space-separated integers -- the checkout log, one tool id per unit on loan (each id refers to one of the n models above); if m = 0 this line is empty.
Print, in strictly increasing order and space-separated on one line, the ids of every model with zero units currently available. If no model qualifies, print an empty line.
Example 1
Input
3 1 2 2 1 3 3 4 1 1 2 3
Expected
1 2
Explanation
Tool 1 owns 2 copies and its id appears twice in the log, so 0 are available -- it qualifies. Tool 2 owns 1 copy and its id appears once, so 0 are available -- it qualifies. Tool 3 owns 3 copies but its id appears only once, leaving 2 available, so it is excluded. Sorted ascending, the qualifying ids are 1 and 2.
Example 2
Input
2 5 2 7 1 0
Expected
(empty)Explanation
The checkout log is empty (m = 0), so no unit of either tool is on loan; both models have their full stock available and neither qualifies, so the output is an empty line.
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 →