Maintain a list of pending orders under append, sort by (time, table), and delete-by-table commands, printing the list after each query.
Easy3SimulationSortingImplementationArrayInterviewNo attempts yetTime limit2sMemory limit256 MBFor the Inha University festival, the algorithm club CTP opened a diner. Sejin does the cooking and Hansol takes the orders. The food was so good that orders kept coming, and with so many of them piling up, Hansol started mixing up their order.
So each time Hansol takes an order, he writes the table number and the order time on a post-it and hands it to Sejin. Sejin is busy cooking, though, and cannot easily work out the order of the post-its. Tojaengi, who was passing by, offered to write a program that sorts the post-its by time and removes the post-it of a table whose dish is done, but exams are close and he has no time. The program handles the following commands.
order n t: an order comes in from table n at order time t. Put a new post-it at the very back of the post-its you hold.sort: sort the post-its by order time, earliest first. If two post-its have the same order time, the one with the smaller table number goes first.complete n: the dish for table n is done. Remove that table's post-it.You are good at coding. Help Tojaengi write the program and bring Kim's Diner back to life.
The first line contains the number of queries N and the number of tables M. (1≤N,M≤100)
Each of the next N lines contains one command, which is one of order n t, sort, and complete n. (1≤t≤1000, 1≤n≤M)
When complete n is given, table n always has exactly one pending order. A table with no pending order or with two or more pending orders is never completed.
After each command, print on one line the table numbers written on the remaining post-its, from front to back, separated by spaces. If no post-it remains, print sleep.