#K75292. Lexicographically Smallest Permutation with k Increasing Pairs
Lexicographically Smallest Permutation with k Increasing Pairs
Lexicographically Smallest Permutation with k Increasing Pairs
Given two integers ( n ) and ( k ), construct the lexicographically smallest permutation of the integers from (1) to (n) such that there are exactly ( k ) adjacent pairs ((i, i+1)) where the element at position (i) is less than the element at position (i+1). In other words, for a permutation (\textbf{perm} = [p_1, p_2, \dots, p_n]), there must be exactly ( k ) indices ( i ) (with (1 \le i < n)) obeying ( p_i < p_{i+1} ).
For example, when ( n = 5 ) and ( k = 2 ), one valid output is:
(1\ 2\ 5\ 4\ 3).
inputFormat
The input consists of a single line containing two space-separated integers ( n ) and ( k ), where ( n ) ((1 \le n \le 10^5)) is the number of elements in the permutation and ( k ) ((0 \le k < n)) is the number of adjacent increasing pairs required.
outputFormat
Output the lexicographically smallest permutation of the integers (1) to ( n ) that contains exactly ( k ) adjacent increasing pairs. The permutation should be printed on a single line with the numbers separated by a space.## sample
5 2
1 2 5 4 3