An agricultural research station operates several greenhouses, each identified by a unique name. Every greenhouse has a temperature sensor that logs one Celsius reading each time it is checked, tagged with the exact calendar date of that check. For a given reporting month, the station wants a tier report: for every greenhouse that has at least one reading in that month, compute the average of exactly its readings from that month, then classify it as Cool if the average is 15 or below, Hot if the average is 25 or above, and Moderate otherwise. Greenhouses with no readings at all in the target month are left out of the report entirely.
Produce the tier report, one line per qualifying greenhouse, sorted by greenhouse name in ascending order.
Line 1: two integers n and m — the number of greenhouses and the number of temperature readings. Next n lines: each contains one greenhouse name (a non-empty string of at most 20 characters using only letters, digits, and underscores, no spaces) — the i-th of these lines names greenhouse i (1-indexed). All names are distinct. Next line: the target reporting month, written as a string in the form YYYY-MM. Next m lines: each contains a greenhouse index g (1 <= g <= n), a date string in the form YYYY-MM-DD, and an integer Celsius reading r, describing one sensor reading taken for greenhouse g on that date.
Print one line for every greenhouse that has at least one reading whose date falls in the target month, sorted by greenhouse name in ascending lexicographic order. Each line contains the greenhouse name, a single space, then its tier: Cool, Moderate, or Hot. If no greenhouse qualifies, print nothing.
Example 1
Input
2 4 Alpha Beta 2024-06 1 2024-06-01 10 1 2024-06-15 20 2 2024-06-05 30 2 2024-06-20 26
Expected
Alpha Cool Beta Hot
Explanation
Alpha's two June readings average (10+20)/2 = 15, which is at most 15, so Alpha is rated Cool. Beta's two June readings average (30+26)/2 = 28, which is at least 25, so Beta is rated Hot. Sorted by name, Alpha comes before Beta, giving 'Alpha Cool' then 'Beta Hot'.
Example 2
Input
3 3 North South East 2024-01 1 2024-01-10 18 2 2024-02-10 5 3 2024-01-15 20
Expected
East Moderate North Moderate
Explanation
North has one January reading of 18, an average of 18, which falls strictly between 15 and 25, so North is Moderate. South's only reading is dated 2024-02, outside the target month 2024-01, so South has zero qualifying readings and is left out entirely. East has one January reading of 20, an average of 20, so East is Moderate too. Sorted by name, East (E) comes before North (N), giving 'East Moderate' then 'North Moderate'.
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 →