A children's science museum keeps two records: a catalogue of every exhibit (its id, category, and display title), and a visit log of every time a visitor viewed an exhibit, dated by year, month and day. The museum newsletter wants to spotlight exhibits from the 'Junior' category that were actually visited at least once during one specific month.
Given the exhibit catalogue, the visit log, and a target year and month, find the distinct titles of every exhibit that satisfies both conditions: the exhibit's category is exactly the string Junior (case-sensitive -- a category like junior does not match), and the exhibit was visited on at least one date falling within the target year and month (the day of the visit does not matter). Report the qualifying titles in ascending alphabetical (lexicographic) order, one per line, each title appearing only once even if it was visited many times or if two different exhibits happen to share the same title. If no exhibit qualifies, print nothing.
Line 1: two integers E V -- the number of exhibits and the number of visit-log entries.
Next E lines: each describes one exhibit as id category title, where id is an integer, category is a single token with no spaces, and title is the rest of the line (it may itself contain spaces). Exhibit ids are distinct.
Next V lines: each describes one visit as four integers id year month day, meaning the exhibit with that id was visited on that date. Every id appearing here also appears in the exhibit catalogue.
Last line: two integers Y M -- the target year and month.
The qualifying distinct titles, one per line, in ascending lexicographic order. Print zero lines if none qualify.
Example 1
Input
3 4 1 Junior Dinosaur Discovery Hall 2 Junior Space Rocket Zone 3 Physics Motion Playground 1 2024 6 3 2 2024 6 15 1 2024 7 1 3 2024 6 10 2024 6
Expected
Dinosaur Discovery Hall Space Rocket Zone
Explanation
Exhibit 1 ('Dinosaur Discovery Hall', Junior) was visited on 2024-6-3, so it qualifies. Exhibit 2 ('Space Rocket Zone', Junior) was visited on 2024-6-15, so it also qualifies. Exhibit 3 is category 'Physics', not 'Junior', so it is excluded even though it was visited in June 2024. Exhibit 1's extra visit in July 2024 doesn't matter since it already qualified. Sorted alphabetically, the output is 'Dinosaur Discovery Hall' followed by 'Space Rocket Zone'.
Example 2
Input
2 2 1 Junior Butterfly Garden 2 Senior Robotics Lab 1 2023 5 20 2 2023 6 1 2023 6
Expected
(empty)Explanation
Exhibit 1 is Junior category but its only visit was in May 2023, not the target June 2023. Exhibit 2 was visited in June 2023 but its category is 'Senior', not 'Junior'. Neither exhibit qualifies, so the output is empty.
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 →