Editorial for The DMOJ Driveway

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.

Author: magicalsoup

Ironically, the implementation of this question is to use a double ended queue, where we can pop from both sides.

When a command is for someone to be pushed into the driveway, just add that person to the end of the deque.

When a command is for someone to be popped out of the driveway, check to see if the person is at the end of the deque. If they are, then pop them out. If they're not, check if they are at the front of deque, and if M \ge 1, then pop them out of the front.

Time Complexity: O(T)


There are no comments at the moment.