#P5010. Longest IBvl Subsequence
Longest IBvl Subsequence
Longest IBvl Subsequence
You are given a sequence of length n and two integers L and R. An IBvl subsequence of the sequence is defined as a subsequence (preserving the original order) satisfying the following condition:
For every consecutive pair in the subsequence, if the subsequence is a1,a2,\ldots,alen, then
\[ \forall\; i\;(2\le i\le len),\quad L< a_i - a_{i-1} < R \]Among all subsequences that satisfy the above condition, an IBvl subsequence is one with the maximum possible length. Note that even if two subsequences have the same values, they are considered different if they are chosen from different positions in the original sequence.
Your task is to output the length of the IBvl subsequence and, among all IBvl subsequences (of maximum length), output the kth smallest one in lexicographical order (based on the indices of the elements in the original sequence). If there is no such subsequence corresponding to the given k, output -1 for the second part.
inputFormat
The first line contains four integers: n, L, R, and k -- where n is the length of the sequence, and L, R define the constraint on consecutive differences, and k is the rank of the subsequence to output.
The second line contains n integers, representing the sequence. The positions are 1-indexed.
outputFormat
Output two lines. The first line contains an integer representing the length of the longest IBvl subsequence. The second line contains the indices (1-indexed) of the elements forming the kth lexicographically smallest IBvl subsequence (the indices are separated by a space). If no such subsequence exists for the given k, output -1 in the second line.
sample
5 1 4 1
1 2 3 5 6
2
2 4
</p>