Longest Increasing Subsequence K
Time limit0.25sMemory limit512 MB
Given N distinct integers, print the K-th lexicographically smallest longest increasing subsequence, or -1 if there are fewer than K of them.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Binary search, Sorting
- Solved
- No attempts yet
Problem
Let be the length of the longest increasing subsequence (LIS) of a sequence of integers. There may be one or more LIS. Sort all LIS in lexicographic order, and find the -th sequence.
Two LIS and are different if there is at least one with .
Input
The first line contains and . The second line contains , separated by spaces.
Output
Print the -th LIS, with its elements separated by spaces. If the -th LIS does not exist, print .
Constraints
- No two elements of the sequence are equal.