Longest Increasing Subsequence K
Time limit0.25sMemory limit512 MB
Given a sequence of N integers and K, find the K-th longest increasing subsequence in lexicographic order of index sequences, or print -1 if fewer than K exist.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Binary search, Combinatorics
- Solved
- No attempts yet
Problem
Let be the length of the longest increasing subsequence (LIS) of a sequence of integers . There can be one or more LISes. Sort all LISes in lexicographic order and find the -th sequence.
Two LISes 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 -1.