Problem:
Score : 700 points

Problem Statement

Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:

The length of its longest increasing subsequence is A.

The length of its longest decreasing subsequence is B.

If it exists, construct one such sequence.

Notes

A subsequence of a sequence P is a sequence that can be obtained by extracting some of the elements in P without changing the order.

A longest increasing subsequence of a sequence P is a sequence with the maximum length among the subsequences of P that are monotonically increasing.

Similarly, a longest decreasing subsequence of a sequence P is a sequence with the maximum length among the subsequences of P that are monotonically decreasing.

Constraints

1 \leq N,A,B \leq 3\times 10^5

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

If there are no sequences that satisfy the conditions, print -1.

Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed.

Sample Input 1

5 3 2

Sample Output 1

2 4 1 5 3

One longest increasing subsequence of this sequence is {2,4,5}, and one longest decreasing subsequence of it is {4,3}.

Sample Input 2

7 7 1

Sample Output 2

1 2 3 4 5 6 7

Sample Input 3

300000 300000 300000

Sample Output 3

-1

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.*;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.StringTokenizer;

public class Main {

    static int N, A, B;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();

        int[] arr = solve();
        if( arr == null ) {
            System.out.println(-1);
        } else {
            StringJoiner j = new StringJoiner(" ");
            for (int i : arr) {
                j.add(String.valueOf(i));
            }
            System.out.println(j.toString());
        }
    }

    static int[] solve(int n, int a, int b) {
        N = n;
        A = a;
        B = b;
        return solve();
    }

    static int[] solve() {
        if( A + B > N + 1 ) return null;
        if( N > A * B ) return null;


        // LISでカードを並べた気持ちになる
        // 縦にならんだ数がLDSになる模様
        //
        // 例 N = 10, A = 5, B = 3の場合
        // 6 7 8 9 10
        // 2 5
        // 1 3 4
        // => 6 7 8 9 10 2 5 1 3 4

        int[] arr = new int[N];

        // まず LISの長さを確保する
        for (int i = 0; i < A; i++) {
            arr[i] = N - A + i + 1;
        }

        if( B == 1 ) return arr;

        // カードの高さがLDS
        // すでに一枚はならんでいるのでそれを考慮する
        int H = B - 1;
        int W = ((N - A) + (H - 1)) / H;
        int[][] HW = new int[H][W];
        int num = 1;

        // 高さ(LDS分)を確保する
        for (int h = H-1; h >= 0 ; h--) {
            HW[h][0] = num++;
        }

        // 残りを満たす
        for (int h = H-1; h >= 0; h--) {
            for (int w = 1; w < W; w++) {
                if( num <= N - A ) {
                    HW[h][w] = num++;
                }
            }
        }

//        System.out.println(H + " " + W);
//        for (int[] hw : HW) {
//            System.out.println( Arrays.toString(hw) );
//        }

        int idx = A;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if( HW[h][w] != 0 ) {
                    arr[idx++] = HW[h][w];
                }
            }
        }

        return arr;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}