Abul Fazl n n arranged the watermelons in a row. He wants to give each watermelon a…
- User
Abul Fazl n n arranged the watermelons in a row. He wants to give each watermelon a unique natural number 1 1 to n assign n Then at the beginning of each day, choose any watermelon that has a smaller number than the one on your right (if any) and eat them all on the same day.
For example, if the numbers on watermelons ⟨ 1 , 5 , 2 , 4 , 6 , 3 ⟩ ⟨1,5,2,4,6,3⟩, after one day it becomes ⟨ 5 , 6 , 3 ⟩ ⟨5,6,3⟩ and after another day become ⟨ 6 , 3 ⟩ becomes ⟨6,3⟩ and does not change in the following days. In this example, Abolfazl first watermelons (with no 1 1), third (with no 2 2) and fourth (with no 4 4) on the first day, and the second watermelon (with no 5 5) on the second day and the fifth watermelons (with no 6 6) and sixth (with no 3 3) never eats.
A numbering of watermelons is "favorable" if per i i if b i
1 b i Let =−1 be watermelon i Iam should never be eaten and otherwise during the day b i b i be eaten to Abul Fazl k Tell me the most beautiful numbering of Abolfazlpasand.
a permutation p 1 , p 2 , . . . , p n p 1 ,p 2 ,...,p n from permutation q 1 , q 2 , . . . , q n q 1 Q 2 ,...,q n It is more beautiful if the amount i i there exists that for every J < i j<i position k k exists that p k
J p k = j and q k
J q k =j and if p x
i p x =i and q y
i q y =i, x < y x<y also holds. Note that being more beautiful is different from being smaller in terms of libraries.
It can be proved that if p p from permutation q q and permutation q q from permutation r r is more beautiful, then it is replaced p p from permutation r r is also more beautiful.
input In the first line of the input n n, the number of watermelons and then k k come in order.
In the next line n n number b 1 , b 2 , . . . , b n b 1 ,b 2 ,..., b n They come in order.
1 ≤ n ≤ 1 0 5 1≤n≤10 5
1 ≤ k ≤ 10 1≤k≤10
1 ≤ b i ≤ n −1≤b i ≤n b i ≠ 0 b i
=0
output If less than k There was a numbering of Abolfazl Pasand
1 −1 and otherwise k Output the most beautiful numbering of Abolfazlpasand.
Sub-issues Constraint score subproblem 1 7 n ≤ 10 n≤10 2 25 n ≤ 2000 n≤2000 3 31 k ≤ 1 k≤1 4 18 k ≤ 2 k≤2 5 19 without additional restrictions Example Sample entry 1 5 1 1 2 1 -1 -1 Plain text Sample output 1 1 3 2 5 4 Plain text Sample input 2 5 2 1 2 1 -1 -1 Plain text Sample output 2 1 4 2 5 3 Plain text Sample entry 3 5 10 1 2 1 -1 -1 Plain text Sample output 3 -1 c++
- Assistant