Declining Sequences
Time limit1sMemory limit128 MB
Given a sequence and a fixed length p, count and return the lexicographically k-th decreasing index sequence for each query.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Binary search
- Solved
- No attempts yet
Problem
Consider an integer sequence . A strictly increasing sequence of indices (with ) is called declining if the values at those positions strictly decrease, that is .
A sequence of indices is lexicographically smaller than a sequence if there is some position such that for every and .
Answer several queries of the form: find the lexicographically -th smallest declining sequence of indices. Every declining sequence considered has length exactly .
Input
The first line contains three integers , , and (, ): the length of the sequence, the length of the declining sequences to consider, and the number of queries. The second line contains integers (). Each of the next lines contains one integer ().
Output
Print lines. The -th line contains the -th smallest declining sequence of indices, written as its index values separated by single spaces, or a single number if that declining sequence does not exist.
Note
For the first example ( and the sequence ), the declining sequences of indices of length , in lexicographic order, are , , , and .