Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb. Question by Ibrahim Mesecan.
Books Waiting
Question:
The library is moving to the new facility.
At the same time, the administration wants to record
the books to the new library program system. They bring bunch
of books all the time and put them to the registration office desk.
The registration officer, takes the books one by one and registers
them to the system (remove from the stack).
Write a program, that reads a list and a sequence
of instructions. Then show the final list after
following the instructions.
Input specification
You will be given an integer in the beginning (n)
the number of instructions. Every instruction listed
in a line and starts with a letter P (Place new books
to the desktop) or R (Remove books from the desktop):
- After the letter P: you are given
a number m: the number of new
books. Then, you are given the IDs of m new books that
have just arrived.
- After the letter R: you are given a number k,
The officer have recorded k books from the top
of the lists (removed from the stack of books).
where 0 ≤ n ≤ 5,000 and 0 ≤ m ≤ 100
Output specification:
Show the IDs of the books still waiting on the desktop.
Show a zero "0" if there is no book waiting.
Sample Input I
4
P 3 11 76 5
R 1
P 2 13 58
R 2
|
Sample Input 2
7
P 5 68 3 10 100 99
P 6 28 4 33 47 80 15
R 6
R 2
P 3 26 9 61
R 4
P 3 59 52 53
|
Sample Output I
76 11
|
Sample Output 2
53 52 59 3 68
|
Explanation: There 4 instructions. The first
instruction tells to place 3 books to desktop. Then one book is
removed (book with the ID 5). Then two new books are placed to
the desktop. And then two books have been recorded and
removed by the officer. So, there are only two books waiting
on the desktop: books 76 and 11.
Для отправки решений необходимо выполнить вход.
|