luogu#P4785. [BalticOI 2016] 交换 (Day2)
[BalticOI 2016] 交换 (Day2)
Problem Description
You are given a sequence containing numbers. Each number appears in the sequence exactly once.
You may modify this sequence by swapping. You must perform consecutive rounds of operations, numbered . In round , you may choose to swap and , or do nothing.
If there exists a number such that for all , holds, and , then the sequence is "lexicographically smaller" than the sequence .
What is the lexicographically smallest sequence you can obtain?
Input Format
The first line contains an integer .
The second line contains integers, representing the sequence .
Output Format
Output integers, representing the lexicographically smallest sequence you can obtain.
5
3 4 2 5 1
2 1 3 4 5
Hint
| Subtask | Score | Constraints |
|---|---|---|
| 1 | 10 | |
| 2 | 11 | |
| 3 | 27 | |
| 4 | 20 | |
| 5 | 32 |
Translated by ChatGPT 5