#P1750. 出栈序列
出栈序列
Description
Given a sequence of elements, you need to push its elements in order into a stack of capacity 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 .
The second line contains numbers, the values of the elements in the sequence.
Output Format
Output numbers, the sequence that meets the requirement.
6 3
5 2 3 8 7 4
2 3 5 4 7 8
Hint
For of the testdata, . For of the testdata, , and each element lies in .
Translated by ChatGPT 5
京公网安备 11011102002149号