#P9270. Tram Seating Assignment
Tram Seating Assignment
Tram Seating Assignment
You are given a series of events representing passengers entering (E
) and leaving (L
) a tram. Initially, the tram is empty. Each event is numbered from \(1\) to \(m\) in chronological order.
There are two types of events:
- E: A passenger enters the tram.
- L: A passenger leaves the tram. For this event, an integer \(p\) is provided, meaning that the passenger leaving entered in event \(p\).
Whenever a passenger enters the tram, there is guaranteed to be at least one empty seat. The seating assignment works as follows: when a passenger enters, they take the smallest available seat number. When a passenger leaves, their seat becomes available again.
Your task is to output the seat number each entering passenger takes at the moment of entry. Only output seat numbers for E
events, in the order they occur.
inputFormat
The first line contains an integer \(m\) (the number of events). The following \(m\) lines each describe an event. An event is in one of the two formats:
E
for an entry event.L p
for a leaving event, where \(p\) is an integer indicating the event number when the leaving passenger entered.
outputFormat
For every entry event (E
), output a line containing a single integer, which is the seat number taken by that passenger when they entered the tram.
sample
4
E
E
L 1
E
1
2
1
</p>