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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

inline int get_max(const vec< int >& f, int p) {
    int r = 0;
    for(int cur = p;cur >= 0;cur = (cur & (cur + 1)) - 1) {
        r = max(r, f[cur]);
    }
    return r;
}

inline void upd(vec< int >& f, int p, int x) {
    for(int cur = p;cur < (int)f.size();cur |= (cur + 1)) {
        f[cur] = max(f[cur], x);
    }
}

int inc(const vec< int >& a) {
    int n = (int)a.size();
    vec< int > f(n + 1, 0);
    int r = 0;
    for(int i = 0;i < n;i++) {
        int x = get_max(f, a[i] - 1) + 1;
        r = max(r, x);
        upd(f, a[i], x);
    }
    return r;
}

bool check(int n, int a, int b, vec< int > p) {
    vec< int > p2 = p;
    for(int i = 0;i < n;i++) {
        p2[i] = n + 1 - p2[i];
    }
    if(inc(p) == a && inc(p2) == b) {
        return true;
    }
    return false;
}

bool brute(int n, int a, int b, vec< int >& res) {
    vec< int > p(n);
    for(int i = 0;i < n;i++) {
        p[i] = i + 1;
    }
    do {
        vec< int > p2 = p;
        for(int i = 0;i < n;i++) {
            p2[i] = n + 1 - p2[i];
        }
        if(inc(p) == a && inc(p2) == b) {
            res = p;
            return true;
        }
    }while(next_permutation(ALL(p)));
    return false;
}

bool solve(int n, int a, int b, vec< int >& res) {
    if(a + b - 1 > n) {
        return false;
    }
    if(a == 1) {
        if(b == 1) {
            if(n == 1) {
                res = {1};
                return true;
            }else {
                return false;
            }
        }else {
            if(b == n) {
                res.clear();
                for(int i = n;i >= 1;i--) {
                    res.push_back(i);
                }
                return true;
            }else {
                return false;
            }
        }
    }
    if(b == 1) {
        if(a == 1) {
            if(n == 1) {
                res = {1};
                return true;
            }else {
                return false;
            }
        }else {
            if(a == n) {
                res.clear();
                for(int i = 1;i <= n;i++) {
                    res.push_back(i);
                }
                return true;
            }else {
                return false;
            }
        }
    }

    int flag = 0;

    if(a < b) {
        swap(a, b);
        flag = 1;
    }

    if(a <= 3) {
        if(n > 9) {
            return false;
        }
        if(!brute(n, a, b, res)) {
            return false;
        }
        if(flag) {
            for(int& x : res) x = n + 1 - x;
        }
        return true;
    }

    if(1ll * (a - 1) * b < n) {
        return false;
    }

    int empt = n - a;
    int last = 0;

    for(int i = 1;i <= a;i++) {
        int ad = min(empt, b - 1);
        empt -= ad;
        ad++;
        for(int x = last + ad;x > last;x--) {
            res.push_back(x);
        }
        last += ad;
    }

    if(flag) {
        for(int& x : res) x = n + 1 - x;
    }

    return true;
}

bool random_solve(int n, int a, int b, vec< int >& res) {
    vec< int > p(n);
    for(int i = 0;i < n;i++) {
        p[i] = i + 1;
    }
    const double MAX_TIME = 1.89 * CLOCKS_PER_SEC;
    while(clock() < MAX_TIME) {
        vec< int > p2 = p;
        for(int i = 0;i < n;i++) {
            p2[i] = n + 1 - p2[i];
        }
        if(inc(p) == a && inc(p2) == b) {
            res = p;
            return true;
        }
    };
    return false;
}

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    vec< int > p;
    int n, a, b;

    cin >> n >> a >> b;

    if(n <= 9) {
        if(brute(n, a, b, p)) {
            for(int x : p) {
                cout << x << " ";
            }
            cout << "\n";
        }else {
            cout << "-1\n";
        }
        return 0;
    }

    p.clear();
    if(solve(n, a, b, p)) {
        for(int x : p) {
            cout << x << " ";
        }
        cout << "\n";
        return 0;
    }

    p.clear();
    if(random_solve(n, a, b, p)) {
        for(int x : p) {
            cout << x << " ";
        }
        cout << "\n";
    }else {
        cout << "-1\n";
    }

    return 0;
}