Stk is an empty stack for i = 1 to n : while ( Stk is not empty ) and ( Stk's top > a[i] ) : pop Stk push a[i] b[i]=Stk's sizeBut he somehow forgot the permutation
The first line contains two integers,
— the length of the permutation, the number of left
.
Thenlines each contains two integer
, denoting that
.
Output one line with n integers— a possible permutation.
If no such permutation exists, output one integer -1.
It's guaranteed that, and
.