

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
がちょうど 回ずつ現れる数列 が与えられます。
あなたは以下の操作のうち つを選んで行うことを 回以上 回以下繰り返せます。
- の項を つ選び、削除する。
- の末尾の項を先頭に移動させる。
操作後の として考えられるもののうち辞書順で最小のものを求めてください。
制約
- には がちょうど 回ずつ現れる。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
操作後の として考えられるもののうち辞書順で最小のものを空白区切りで出力せよ。
入力例 1Copy
5 3 4 5 2 3 1
出力例 1Copy
1 2 3
以下のように操作をすると は になります。
- 先頭の項を削除する。これによって は になる。
- 末尾の項を先頭に移動させる。これによって は になる。
- 先頭から 番目の項を削除する。これによって は になる。
また、辞書順で より小さい数列は操作後の として考えられません。よってこれが答えです。
入力例 2Copy
3 0 3 2 1
出力例 2Copy
3 2 1
操作を 回も行えない場合があります。
入力例 3Copy
15 10 12 10 7 2 8 11 9 1 6 14 3 15 13 5 4
出力例 3Copy
1 3 4 7 2 8 11 9
Score : points
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 1Copy
5 3 4 5 2 3 1
Sample Output 1Copy
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 2Copy
3 0 3 2 1
Sample Output 2Copy
3 2 1
You may be unable to perform operations.
Sample Input 3Copy
15 10 12 10 7 2 8 11 9 1 6 14 3 15 13 5 4
Sample Output 3Copy
1 3 4 7 2 8 11 9