NMK

Time limit2sMemory limit128 MB

Summary
Construct a permutation of 1..N whose longest increasing subsequence is exactly M and longest decreasing subsequence is exactly K, or report impossible.
Level

Medium6 of 10

Topics
Combinatorics, Greedy, Math, Array
Solved
No attempts yet

Problem

Use each integer from 1 through N exactly once to form a sequence.

The sequence must have longest strictly increasing subsequence length exactly M, and longest strictly decreasing subsequence length exactly K.

Print one sequence satisfying these conditions.

Input

The first line contains three integers N, M, and K.

Output

Print a sequence satisfying the conditions on one line, with numbers separated by spaces.

If no such sequence exists, print -1.

Constraints

  • 1 <= N <= 500
  • 1 <= M, K <= N

Examples5

  1. Example 1

    Input
    4 2 2
    
    Expected output
    2 1 4 3
    
  2. Example 2

    Input
    4 4 1
    
    Expected output
    1 2 3 4
    
  3. Example 3

    Input
    4 3 2
    
    Expected output
    1 4 2 3
    
  4. Example 4

    Input
    4 4 2
    
    Expected output
    -1
    
  5. Example 5

    Input
    13 5 4
    
    Expected output
    1 3 2 13 10 11 12 6 8 9 4 5 7