Longest Increasing Subsequence ks
Time limit0.25sMemory limit512 MB
Given a permutation-like sequence, find the K-th longest increasing subsequence when all LISs are sorted lexicographically by index, or -1 if fewer than K exist.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Combinatorics, Binary search
- Solved
- No attempts yet
Problem
For a sequence of integers , let be the length of the longest increasing subsequence (LIS). There may be one or more LISs. Sort all LISs in lexicographic order and find the K-th one.
Given two LISs and , they are different LISs if there is at least one with .
Input
The first line gives N and K. The second line gives separated by spaces.
Output
Print the K-th LIS separated by spaces. If the K-th LIS does not exist, print -1.
Constraints
- The sequence A has no duplicate numbers.