#P9518. Queue Maintenance in Amusement Parlor
Queue Maintenance in Amusement Parlor
Queue Maintenance in Amusement Parlor
In an arcade, there is a single game machine that can accommodate at most two persons at a time. However, more than two people arrive to play, so they need to queue. In this problem, you need to simulate the queue management and handle the following events:
start
: A game starts. If this is not the first game, then the participants from the previous game (in their original order) are appended to the tail of the queue just before the current game starts. Then, from the front of the queue, at most two persons are selected as players of the current game. Their names (if two, separated by a single space) are printed. If no one is available in the queue, outputError
and ignore this event.arrive x
: Person $x$ arrives at the arcade and joins the tail of the queue. If $x$ is already in the queue (including those who are playing, i.e. the first two persons in the queue), outputError
and ignore this event. Otherwise outputOK
.leave x
: Person $x$ leaves the arcade and exits the queue. At the moment of leaving, $x$ must be in the queue but must not be one of the players currently playing (i.e. not among the first two in the queue). If this is not the case, outputError
and ignore this event. Otherwise outputOK
.
Note: Unlike traditional queues, the players currently playing (i.e. the first two in the queue) are considered as still being in the queue.
inputFormat
The input consists of several lines, each line representing an event. Each event is of one of the following forms:
start
arrive x
where $x$ is a string representing the name of the person.leave x
where $x$ is a string representing the name of the person.
Process events in the order they appear until the end of input.
outputFormat
For each event, output the corresponding response as described below:
- For a successful
arrive
orleave
event, outputOK
. - For a successful
start
event, output the names of the players playing in the current game (either one or two names separated by a single space). - For any event that is invalid according to the rules, output
Error
.
sample
arrive Alice
arrive Bob
start
arrive Charlie
start
leave Charlie
start
OK
OK
Alice Bob
OK
Charlie Alice
Error
Bob Charlie
</p>