atcoder#ABC223D. [ABC223D] Restricted Permutation
[ABC223D] Restricted Permutation
Score : points
Problem Statement
Among the sequences that are permutations of and satisfy the condition below, find the lexicographically smallest sequence.
- For each , appears earlier than in .
If there is no such , print -1
.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4 3
2 1
3 4
2 4
2 1 3 4
The following five permutations satisfy the condition: $(2, 1, 3, 4), (2, 3, 1, 4), (2, 3, 4, 1), (3, 2, 1, 4), (3, 2, 4, 1)$. The lexicographically smallest among them is .
2 3
1 2
1 2
2 1
-1
No permutations satisfy the condition.