A community library logs two independent streams of activity: every time a patron badges into the reading room (a sign-in session), and every time a book is checked out, with each checkout tagged with the sign-in session during which it happened. A single session can have any number of checkouts, including none at all. The head librarian wants to identify, for each patron, how many of that patron's sessions were completely checkout-free.
Line 1: two integers S and C — the number of sign-in sessions and the number of checkout records.
Next S lines: two integers sessionId patronId — sessionId is unique across the S lines, and patronId identifies which patron owns that session (a patron may own many sessions).
Next C lines: two integers checkoutId sessionId — checkoutId is unique across the C lines, and sessionId refers to one of the sessions listed above.
For every patron who has at least one checkout-free session, print a line patronId count, where count is the number of that patron's sessions that had zero checkouts. Print one line per qualifying patron, sorted by patronId ascending. If no patron qualifies, print nothing.
sessionId that appears among the checkout records also appears among the sign-in sessionsExample 1
Input
3 1 1 100 2 100 3 200 10 1
Expected
100 1 200 1
Explanation
Sessions 1 and 2 belong to patron 100, session 3 belongs to patron 200. The single checkout record targets session 1, leaving session 2 (patron 100) and session 3 (patron 200) checkout-free. Each of those patrons has exactly one checkout-free session, so the output is "100 1" then "200 1" (sorted by patronId).
Example 2
Input
4 2 1 5 2 5 3 5 4 9 100 2 101 4
Expected
5 2
Explanation
Patron 5 owns sessions 1, 2 and 3; patron 9 owns session 4. Checkouts cover sessions 2 and 4, leaving sessions 1 and 3 (both patron 5) checkout-free while session 4 (patron 9) is covered. Patron 5 therefore has 2 checkout-free sessions and patron 9 has none, so the only output line is "5 2".
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 →