P1750 Stack Pop Sequence
Description
Given a sequence of $n$ elements, you need to push its elements in order into a stack of capacity $c$ and pop them. Arranging the elements according to their pop order yields a new sequence. There can be many such sequences; among all new sequences, output the one whose first element is the smallest (if there are multiple with the smallest first element, make the second as small as possible; if still multiple, make the third smallest, and so on).
Input Format
The first line contains two integers $n, c$.
The second line contains $n$ numbers, the values of the $n$ elements in the sequence.
Output Format
Output $n$ numbers, the sequence that meets the requirement.
Explanation/Hint
For $40 \%$ of the testdata, $n \le 12$.
For $100 \%$ of the testdata, $1 \le c \le n \le 10000$, and each element lies in $[1, 2 \times {10}^9]$.
Translated by ChatGPT 5