P5184 [COCI 2009/2010 #2] PASIJANS
Background
The original time limit was 5 s. The time limit here has been adjusted according to the speed of Luogu's judge machines.
Description
**Translated from [COCI 2009.11](http://hsin.hr/coci/archive/2009_2010/) T6 “[PASIJANS](http://hsin.hr/coci/archive/2009_2010/contest2_tasks.pdf)”**
You are given $N$ stacks that already contain numbers (the number of elements in each stack may be different), and an empty “answer queue”. Each time, you may “pop the top element of one stack and append it to the end of the answer queue”, until all stacks become empty. Find the lexicographically smallest possible answer queue.
If two answer queues $a, b$ (from front to back) have the same first $i-1$ numbers, and $a_i
Input Format
The first line contains an integer $N$.
In the next $N$ lines, the first integer is $L$, the number of elements in the stack. Then $L$ integers are given in order from the top of the stack to the bottom.
Output Format
Output $\sum L$ integers, representing the lexicographically smallest answer queue.
Explanation/Hint
$1\le N\le 1000,$ $1\le L\le 1000$。
Translated by ChatGPT 5