#K45502. Average Trip Duration
Average Trip Duration
Average Trip Duration
This problem asks you to calculate the average duration of valid trips based on start and end timestamps. Each trip is represented by its start time and end time in the \(YYYY\text{-}MM\text{-}DD \ HH:MM:SS\) format. For each trip, if the start time is not before the end time, you must print the error message \(\text{Start time must be before end time}\) on a new line and ignore that trip when computing the average. If there are no valid trips or the input list is empty, output 0. Otherwise, compute the average duration (in minutes) of all valid trips and round it to the nearest minute.
inputFormat
The input is provided via standard input. The first line contains an integer \(T\) representing the number of trips. Each of the following \(T\) lines contains two timestamps representing the start and end times of a trip. Each timestamp is in the format \(YYYY-MM-DD HH:MM:SS\) and exactly 19 characters long. The two timestamps on a line are separated by a space.
outputFormat
Output the results via standard output. For every trip where the start time is not before the end time, print the line "Start time must be before end time" (each on its own line). After processing all trips, if at least one valid trip exists, print the average duration (rounded to the nearest minute) on a new line. If there are no valid trips, print 0.
## sample3
2023-10-01 08:00:00 2023-10-01 08:30:00
2023-10-01 09:10:00 2023-10-01 09:50:00
2023-10-02 12:00:00 2023-10-02 12:25:00
32
</p>