#K5036. Maximum Plant Population in Date Range
Maximum Plant Population in Date Range
Maximum Plant Population in Date Range
You are given a set of observations for various regions. Each observation contains a region identifier, a date (formatted as \(YYYY-MM-DD\)), and the plant population recorded on that day. Your task is to compute the maximum plant population for each region during a specified date range \( [\text{start\_date}, \text{end\_date}] \).
If there are no observations within the specified range, output an empty dictionary {}
. For each region with at least one valid observation, output the region identifier followed by its maximum population, one pair per line in ascending order of region id.
Note: The dates provided are in ISO 8601 format. You are encouraged to use appropriate date parsing methods to compare dates.
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains two space-separated strings:
start_date
andend_date
. - The second line contains an integer
n
, the number of observations. - The next
n
lines each contain an observation in the format:region_id date population
, where: region_id
is an integer.date
is a string in the format \(YYYY-MM-DD\).population
is an integer.
outputFormat
The output should be written to standard output (stdout). For each region that has at least one observation in the specified date range, print a line containing the region id and the maximum population in that region, separated by a space, sorted in increasing order by region id. If no observations fall within the date range, output {}
(without quotes).
2022-01-01 2022-02-28
5
1 2022-01-15 150
2 2022-01-16 200
1 2022-02-10 180
2 2022-02-15 220
1 2022-03-05 170
1 180
2 220
</p>