atcoder#AGC046E. [AGC046E] Permutation Cover
[AGC046E] Permutation Cover
Score : points
Problem Statement
Given are an integer and integers . Determine whether a sequence satisfying below exists. If it exists, find the lexicographically smallest such sequence.
- Every term in is an integer between and (inclusive).
- For each , contains occurrences of .
- For each term in , there is a contiguous subsequence of length that contains that term and is a permutation of .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If there is no sequence satisfying the conditions, print -1
.
Otherwise, print the lexicographically smallest sequence satisfying the conditions.
3
2 4 3
2 1 3 2 2 3 1 2 3
For example, the fifth term, which is , is in the subsequence composed of the fifth, sixth, and seventh terms.
4
3 2 3 2
1 2 3 4 1 3 1 2 4 3
5
3 1 4 1 5
-1