#P7957. Construct a Permutation with Given Longest Increasing Subsequence Length

    ID: 21141 Type: Default 1000ms 256MiB

Construct a Permutation with Given Longest Increasing Subsequence Length

Construct a Permutation with Given Longest Increasing Subsequence Length

You are given two integers $$n$$ and $$k$$. Your task is to construct a permutation of $$\{1,2,\dots,n\}$$ such that its Longest Increasing Subsequence (LIS) has exactly length $$k$$.

A permutation is an arrangement of the numbers from $$1$$ to $$n$$. The Longest Increasing Subsequence of a sequence is defined as the longest subsequence in which the elements are in strictly increasing order.

Hint: One way to guarantee that the longest increasing subsequence is exactly $$k$$ is to divide the sequence into $$k$$ blocks. In each block, arrange the numbers in descending order. This way, any increasing subsequence can pick at most one element from each block, and by picking the smallest element from each block, you can form an increasing sequence of length exactly $$k$$.

inputFormat

The input consists of a single line containing two space-separated integers $$n$$ and $$k$$, where $$1 \leq k \leq n$$.

outputFormat

Output a permutation of the integers from $$1$$ to $$n$$ (space-separated) that has a longest increasing subsequence of length exactly $$k$$.

sample

5 3
2 1 4 3 5