Holiday in the store
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Kondrat works in a grocery store. He has wanted to rearrange the goods on his shelves for a long time, but could never find the time for it. And then the 47th day of the year arrived. On this festive day, the store is usually visited by many customers, so one must act quickly. Kondrat knows that people like to buy cheap goods, and he wants to try an interesting strategy.
Kondrat has \(n\) different goods in the store, numbered with integers from 1 to \(n\) inclusive. The price of the good numbered \(i\) is equal to \(i\) hryvnias. On the Internet, Kondrat read that the maximum number of goods can be sold if they are arranged in a row, and among them there are exactly \(k\) attractive ones. People consider a good to be attractive if directly to the left and to the right of this good there are other goods with higher prices. Note that the leftmost and rightmost goods cannot be attractive because they have only one neighbor each.
Help Kondrat to correctly arrange all the goods.
Input
The single line contains two integers \(n\) and \(k\).
Output
Print \(n\) integers — the desired permutation of goods.
If there are several such permutations, you are allowed to print any of them.
If such a permutation does not exist — print -1.
Constraints
\(1 \le n \le 10^5\),
\(0 \le k \le n\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 7 1 | 7 6 5 1 2 3 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| 7 7 | -1 |
Notes
In the example from the statement, only the good with price 1 has neighboring goods with a higher price. For all other goods, at least one of the neighbors is smaller.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Holiday in the store - Editorial
We need to generate a permutation of \(n\) numbers with exactly \(k\) local minima (numbers whose neighbors are greater than the number itself), or say that this is impossible.
Clearly, there cannot be more than \(\frac{n-1}{2}\) local minima. So when \(k > \frac{n-1}{2}\), we print
-1.
To create a local minimum in a permutation, it is enough to swap two adjacent numbers of an increasing sequence. To create \(k\) local minima, we just make \(k\) such swaps. For example:
\(1 2 3 4 5 6 7 \rightarrow 1 \Leftrightarrow 2 3 \Leftrightarrow 4 5 \Leftrightarrow 6 7 \rightarrow 2 1 4 3 6 5 7\)
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|