#abc262f. F - Erase and Rotate
F - Erase and Rotate
Score : points
问题描述
你得到一个序列 ,其中恰好包含每个数字 各一次。
你可以按任意顺序总共执行以下操作零次到 次:
- 选择 中的一个元素并移除它。
- 将 的最后一个元素移动到头部。
找出经过这些操作后可以获得的字典序最小的 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence that contains exactly once each.
You may perform the following operations between and times in total in any order:
- Choose one term of and remove it.
- Move the last term of to the head.
Find the lexicographically smallest that can be obtained as a result of the operations.
Constraints
- contains exactly once each.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the lexicographically smallest that can be obtained as a result of the operations, separated by spaces.
Sample Input 1
5 3
4 5 2 3 1
Sample Output 1
1 2 3
The following operations make equal .
- Removing the first term makes equal .
- Moving the last term to the head makes equal .
- Removing the second term makes equal .
There is no way to obtain lexicographically smaller than , so this is the answer.
Sample Input 2
3 0
3 2 1
Sample Output 2
3 2 1
You may be unable to perform operations.
Sample Input 3
15 10
12 10 7 2 8 11 9 1 6 14 3 15 13 5 4
Sample Output 3
1 3 4 7 2 8 11 9
update @ 2024/3/10 11:06:22