Editorial for TLE '15 P2 - Microwaves


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

First, sort all people by arrival time.

Realize that the person at the front of the line should never wait if a microwave can be chosen. Then, we notice that we can use a greedy solution: the person at the front of the line should choose the microwave that most recently ended, since we want TT1103 to use the earliest microwave possible. If no such microwave exists, that person should pick the first microwave that will become available in order to shorten the line. When choosing a microwave, compare the microwave's most recent end time with the person's start time. If the difference is greater to or equal to T, it is possible for TT1103 to use the microwave starting from the most recent end time. After everybody is done, make sure that the microwave with the earliest previous end time is checked. Output the smallest time that is found.

A multiset can be used to quickly choose the microwave for each person to use, but it is not mandatory.

Also, make sure that 64-bit integers are used.

Time Complexity: \mathcal{O}(M \log M)


Comments

There are no comments at the moment.