A neighborhood bakery keeps a menu of items and a log of every order placed for them. At the end of each month the owner wants to know which menu items sold well enough to justify restocking: every item whose combined quantity ordered during one specific year and month is at least a given threshold.
You are given the bakery's menu, its full order log, and the target year, month, and threshold. For every menu item that received at least one order in the target year and month, compute the total quantity ordered for that item during that month. Report the name and total for every such item whose total is greater than or equal to the threshold, sorted by name in ascending (lexicographic) order. An item that received no orders at all in the target month is never reported, even if the threshold is 0.
Line 1: two integers n and m -- the number of menu items and the number of orders. Each of the next n lines contains an integer id and a string name (no spaces, distinct across items) -- one menu item. The next line contains three integers year, month, and threshold. Each of the next m lines contains an integer id, a string date in the exact format YYYY-MM-DD, and an integer quantity -- one order for the menu item with that id.
For every qualifying item (as defined above), print a line with its name and its total quantity ordered in the target month, separated by a single space, sorted by name ascending. If no item qualifies, print NONE.
1 <= n <= 1000 0 <= m <= 2000 1 <= id <= n, and every order's id refers to an existing menu item 1 <= quantity <= 1000 2000 <= year <= 2100, 1 <= month <= 12 0 <= threshold <= 10^6 Names consist of 1 to 20 lowercase English letters and are pairwise distinct.
Example 1
Input
3 5 1 croissant 2 bagel 3 muffin 2020 2 100 1 2020-02-01 60 1 2020-02-10 50 2 2020-02-05 30 2 2020-01-15 999 3 2020-02-20 10
Expected
croissant 110
Explanation
In February 2020, croissant received orders of 60 and 50 units (total 110, which meets the threshold of 100). Bagel received only the 30-unit order in February -- the 999-unit order was placed in January and is excluded -- giving a February total of 30, below 100. Muffin's February total is 10, also below 100. Only croissant qualifies, so the output is "croissant 110".
Example 2
Input
3 5 1 croissant 2 bagel 3 muffin 2020 2 1000 1 2020-02-01 60 1 2020-02-10 50 2 2020-02-05 30 2 2020-01-15 999 3 2020-02-20 10
Expected
NONE
Explanation
With the same orders but the threshold raised to 1000, none of the February 2020 totals (110, 30, and 10) reach it, so no item qualifies and the output is NONE.
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 →