atcoder#ABC262F. [ABC262F] Erase and Rotate
[ABC262F] Erase and Rotate
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.
5 3
4 5 2 3 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.
3 0
3 2 1
3 2 1
You may be unable to perform operations.
15 10
12 10 7 2 8 11 9 1 6 14 3 15 13 5 4
1 3 4 7 2 8 11 9