C - K Derangement 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 600

問題文

正整数 N, K が与えられます. 1 から N までの整数からなる順列 A = (A_1, A_2, \ldots, A_N) であって次の条件を満たすもののうち, 辞書順最小のものを求めてください.

  • 任意の i (1\leq i\leq N) に対して \lvert A_i - i\rvert \geq K が成り立つ.

そのような順列が存在しない場合には,-1 を出力してください.

数列の辞書順とは?

相異なる数列 S と数列 T の大小を判定するアルゴリズムを以下に説明します.

以下では Si 番目の要素を S_i のように表します.また, ST より辞書順で小さい場合は S \lt T ,大きい場合は S \gt T と表します.

  1. ST のうち長さが短い方の文字列の長さを L とします.i=1,2,\dots,L に対して S_iT_i が一致するか調べます.
  2. S_i \neq T_i である i が存在する場合,そのような i のうち最小のものを j とします.そして,S_jT_j を比較して, S_jT_j より(数として)小さい場合は S \lt T ,大きい場合は S \gt T と決定して,アルゴリズムを終了します.
  3. S_i \neq T_i である i が存在しない場合, ST の長さを比較して,ST より短い場合は S \lt T ,長い場合は S \gt T と決定して,アルゴリズムを終了します.

制約

  • 2\leq N\leq 3\times 10^5
  • 1\leq K\leq N - 1

入力

入力は以下の形式で標準入力から与えられます.

N K

出力

条件を満たす順列 A のうち,辞書順最小のものを次の形式で出力してください.

A_1 A_2 \ldots A_N

そのような順列が存在しない場合には,-1 を出力してください.


入力例 1

3 1

出力例 1

2 3 1

条件を満たす順列は,(2, 3, 1)(3, 1, 2)2 つです.例えば (2, 3, 1)

  • \lvert A_1 - 1\rvert = 1 \geq K
  • \lvert A_2 - 2\rvert = 1 \geq K
  • \lvert A_3 - 3\rvert = 2 \geq K

であるため条件を満たしています.


入力例 2

8 3

出力例 2

4 5 6 7 8 1 2 3

入力例 3

8 6

出力例 3

-1

Score : 600 points

Problem Statement

You are given positive integers N and K. Find the lexicographically smallest permutation A = (A_1, A_2, \ldots, A_N) of the integers from 1 through N that satisfies the following condition:

  • \lvert A_i - i\rvert \geq K for all i (1\leq i\leq N).

If there is no such permutation, print -1.

What is lexicographical order on sequences?

The following is an algorithm to determine the lexicographical order between different sequences S and T.

Below, let S_i denote the i-th element of S. Also, if S is lexicographically smaller than T, we will denote that fact as S \lt T; if S is lexicographically larger than T, we will denote that fact as S \gt T.

  1. Let L be the smaller of the lengths of S and T. For each i=1,2,\dots,L, we check whether S_i and T_i are the same.
  2. If there is an i such that S_i \neq T_i, let j be the smallest such i. Then, we compare S_j and T_j. If S_j is less than T_j (as a number), we determine that S \lt T and quit; if S_j is greater than T_j, we determine that S \gt T and quit.
  3. If there is no i such that S_i \neq T_i, we compare the lengths of S and T. If S is shorter than T, we determine that S \lt T and quit; if S is longer than T, we determine that S \gt T and quit.

Constraints

  • 2\leq N\leq 3\times 10^5
  • 1\leq K\leq N - 1

Input

Input is given from Standard Input in the following format:

N K

Output

Print the lexicographically smallest permutation A = (A_1, A_2, \ldots, A_N) of the integers from 1 through N that satisfies the condition, in the following format:

A_1 A_2 \ldots A_N

If there is no such permutation, print -1.


Sample Input 1

3 1

Sample Output 1

2 3 1

Two permutations satisfy the condition: (2, 3, 1) and (3, 1, 2). For instance, the following holds for (2, 3, 1):

  • \lvert A_1 - 1\rvert = 1 \geq K
  • \lvert A_2 - 2\rvert = 1 \geq K
  • \lvert A_3 - 3\rvert = 2 \geq K

Sample Input 2

8 3

Sample Output 2

4 5 6 7 8 1 2 3

Sample Input 3

8 6

Sample Output 3

-1