|
Given a subsequence of a permutation of n elements (1, 2, ..., n ), you have to find the K-th permutation in lexicographic order that contains the subsequence given.
For example:
If you have 1, 3, 2 and n equals to 4 you can obtain these permutations:
Input file contains several test cases. The first line of the test case contains three integers n (1 <= n <= 250), m (0 < m <= n) m is the number of the elements of the subsequence and K , in the next line contains m integers.
For each test case write a K-th permutation that satisfies the condition, one per line.
Notice: K-th position always exists.
Sample Input | Sample Output |
4 3 1 |
1 3 2 4 |
Problemsetter: Rodrigo Burgos Domínguez