atcoder#ARC128E. [ARC128E] K Different Values
[ARC128E] K Different Values
Score : points
Problem Statement
Given are a sequence of integers and an integer .
Consider making a sequence of integers that satisfies both of the following conditions.
- For each integer (), contains exactly occurrences of . does not contain other integers.
- For every way of choosing consecutive elements from , their values are all distinct.
Determine whether it is possible to make that satisfies the conditions. If it is possible, find the lexicographically smallest such .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to make a sequence that satisfies the conditions, print -1
.
If it is possible, print the lexicographically smallest such .
3 3
2 2 1
1 2 3 1 2
Two sequences satisfy the conditions. The lexicographically smaller one, , is the answer.
3 2
2 1 2
1 2 3 1 3
3 3
1 3 3
-1