#K80272. Peak and Least Busy Periods
Peak and Least Busy Periods
Peak and Least Busy Periods
You are given several datasets that each represent traffic data records during a day. Each record contains a time stamp in HH:MM format and a corresponding count, which indicates the number of vehicles recorded at that moment. Your task is to group the counts by the hour (using the hour part of the time stamp) and then determine both the peak hour period (the hour during which the total count is the maximum) and the least busy hour period (the hour during which the total count is the minimum). In case of ties, choose the earliest hour.
Each period must be represented in the format HH:MM-HH:MM where the start is hour:00 and the end is hour:59. For example, if the peak hour is 13 (1 PM), the period should be output as 13:00-13:59.
The input consists of multiple datasets. For each dataset, the first line contains an integer m
denoting the number of records. The following m
lines each contain a time stamp and a count, separated by a space. A dataset with m = 0
indicates the end of input.
inputFormat
The input contains multiple datasets. Each dataset begins with an integer m
on a separate line, representing the number of records in that dataset. The next m
lines each contain a record consisting of a time in HH:MM format and an integer count, separated by a space. The input terminates when m
is zero.
Example:
6 08:00 50 09:30 30 10:45 60 11:15 80 12:30 50 13:00 90 5 00:00 10 01:15 5 03:30 20 04:45 15 06:00 8 0
outputFormat
For each dataset, output a single line containing two time periods separated by a space. The first period corresponds to the peak hour (with the highest total count) and the second period corresponds to the least busy hour (with the lowest total count). Each period is in the format HH:MM-HH:MM.
Example Output:
13:00-13:59 09:00-09:59 03:00-03:59 01:00-01:59## sample
6
08:00 50
09:30 30
10:45 60
11:15 80
12:30 50
13:00 90
5
00:00 10
01:15 5
03:30 20
04:45 15
06:00 8
0
13:00-13:59 09:00-09:59
03:00-03:59 01:00-01:59
</p>