#P7957. [COCI 2014/2015 #6] KRATKI

[COCI 2014/2015 #6] KRATKI

Background

We are all very familiar with the “Longest Monotone Subsequence” problem:

Given a sequence of length nn, you need to find the length of its LMS (i.e., the longest monotone subsequence).
Note that here “LMS” means the longer one between the increasing subsequence and the decreasing subsequence.
That is, you need to take the maximum of the lengths of LIS and LDS.

Now you need to solve an inverse problem of LMS.

Problem Description

Given the length nn of a sequence.

You need to construct a permutation of length nn such that its LMS length is kk.

Input Format

A single line with two integers n,kn, k.

Output Format

If there is no solution, output -1\texttt{-1}.

Otherwise, output one line with nn integers, the sequence you constructed.

If there are multiple solutions, output any one.

4 3
1 4 2 3
5 1
-1
5 5
1 2 3 4 5

Hint

Explanation of Sample 1

The LMS of {1,4,2,3}\{1,4,2,3\} is {1,2,3}\{1,2,3\}, with length 33, which meets the requirement.

Constraints

This problem uses Special Judge.

For 100%100\% of the testdata, 1kn1061 \le k \le n \le 10^6.

Notes

According to the original settings, the full score is 120 points.

Translated from COCI 2014-2015 Contest #6 Task D KRATKI.

Since the original testdata lacked some special cases, testdata #11 has been added to this problem. If you do not pass it, you will get 120 Unaccept.

Translated by ChatGPT 5