cswork / OAOpen practice workspace

SnowflakeOA #31

Meeting Assistant

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesStrings

Each event has the format person action start end, and the occupied start and end minutes are both inclusive. Within 00:00..23:59, find the earliest k consecutive minutes during which everyone who appears in the events is free. Return −1 if there is no solution; the meeting must not cross into the next day.

Input

The first line contains n k, followed by n lines of events; times use the HH:MM format. 1≤n≤100000, 1≤k≤1440, each original event string has length ≤40, the number of people is <5000, and events of the same person do not overlap.

Output

Output the earliest time HH:MM, or −1 if it is impossible.

Example 1

Input:

3 60
Alex busy 00:00 08:00
Sam busy 07:00 13:00
Alex busy 12:30 13:59

Output:

14:00

Example 2

Input:

2 1
sam busy 12:00 23:59
alex busy 00:00 13:00

Output:

-1

Example 3

Input:

2 60
sam busy 12:00 18:59
alex busy 00:00 11:00

Output:

19:00

Example notes

The answers to the three public examples are, in order: 14:00; -1; 19:00. The examples were rechecked by independent enumeration, state search, or direct simulation.

Editorial

Loading solution…