MetaOA #25
Buses in a Bustling Town
Estimated EasyJudge-ready
Topics (AI-labelled)StringsSimulation
Given the day's bus departure times and the current time, find how many minutes ago the most recent bus that has already departed left. A bus scheduled exactly at the current time has not departed yet; it must be strictly earlier than the current time. If there is none, output −1; the previous day is not considered.
Input
This site's input: the first line contains n (0..100000), followed by n lines of HH:MM times, and the last line is the current time. Hours are 00..23 and minutes are 00..59, and all times are on the same day; the timetable may be unsorted and may contain duplicates.
Output
Output the number of minutes, or −1.
Example 1
Input:
3
12:30
14:00
19:55
14:30
Output:
30
Example 2
Input:
3
00:00
14:00
19:55
00:00
Output:
-1
Example 3
Input:
3
12:30
14:00
19:55
14:00
Output:
90
Example notes
Example 1: the last bus that departed left at 14:00, which is 30 minutes before 14:30.
Example 2: the 00:00 bus is exactly at the current time and has not departed yet, so the output is −1.
Example 3: the 14:00 bus has not departed yet; the previous one is 12:30, 90 minutes earlier.
Editorial
Loading solution…