Problem p03421 (C++)

Buggy submission (status: Runtime Error):
/*
Author: CNYALI_LK
LANG: C++
PROG: c.cpp
Mail: cnyalilk@vip.qq.com
*/
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %lld\n", __FUNCTION__, __LINE__)
#define Debug debug("Passing [%s] in LINE %lld\n", __FUNCTION__, __LINE__)
#define all(x) x.begin(), x.end()
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long ll;
typedef pair<ll, ll> pii;
template <class T> ll chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <class T> ll chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <class T> T sqr(T a) { return a * a; }
template <class T> T mmin(T a, T b) { return a < b ? a : b; }
template <class T> T mmax(T a, T b) { return a > b ? a : b; }
template <class T> T aabs(T a) { return a < 0 ? -a : a; }
#define min mmin
#define max mmax
#define abs aabs
ll read() {
  ll s = 0, base = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-')
      base = -base;
  while (isdigit(c)) {
    s = s * 10 + (c ^ 48);
    c = getchar();
  }
  return s * base;
}
char WritellBuffer[1024];
template <class T> void write(T a, char end) {
  ll cnt = 0, fu = 1;
  if (a < 0) {
    putchar('-');
    fu = -1;
  }
  do {
    WritellBuffer[++cnt] = fu * (a % 10) + '0';
    a /= 10;
  } while (a);
  while (cnt) {
    putchar(WritellBuffer[cnt]);
    --cnt;
  }
  putchar(end);
}
ll xu[102424];
int main() {
#ifdef cnyali_lk
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
  ll n, a, b;
  n = read();
  b = read();
  a = read();
  if ((a + b - 1) > n || (a * b < n))
    printf("-1\n");
  else {
    ll s = 0, t = n;
    while (s < n) {
      //			debug("Now%lld\n",s);
      if ((t - b) >= a - 1) {
        for (ll i = 1; i <= b; ++i) {
          xu[++s] = (t - b + i);
        }
        t -= b;
        --a;
      } else {
        for (ll i = 1; i <= t - a + 1; ++i)
          xu[++s] = t - (t - a + 1) + i;
        t = a - 1;
        while (t) {
          xu[++s] = t;
          --t;
        }
      }
    }
    for (ll i = 1; i <= n; ++i)
      printf("%lld%c", xu[i], i == n ? '\n' : ' ');
  }

  return 0;
}


Fixed submission:
/*
Author: CNYALI_LK
LANG: C++
PROG: c.cpp
Mail: cnyalilk@vip.qq.com
*/
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %lld\n", __FUNCTION__, __LINE__)
#define Debug debug("Passing [%s] in LINE %lld\n", __FUNCTION__, __LINE__)
#define all(x) x.begin(), x.end()
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long ll;
typedef pair<ll, ll> pii;
template <class T> ll chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <class T> ll chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <class T> T sqr(T a) { return a * a; }
template <class T> T mmin(T a, T b) { return a < b ? a : b; }
template <class T> T mmax(T a, T b) { return a > b ? a : b; }
template <class T> T aabs(T a) { return a < 0 ? -a : a; }
#define min mmin
#define max mmax
#define abs aabs
ll read() {
  ll s = 0, base = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-')
      base = -base;
  while (isdigit(c)) {
    s = s * 10 + (c ^ 48);
    c = getchar();
  }
  return s * base;
}
char WritellBuffer[1024];
template <class T> void write(T a, char end) {
  ll cnt = 0, fu = 1;
  if (a < 0) {
    putchar('-');
    fu = -1;
  }
  do {
    WritellBuffer[++cnt] = fu * (a % 10) + '0';
    a /= 10;
  } while (a);
  while (cnt) {
    putchar(WritellBuffer[cnt]);
    --cnt;
  }
  putchar(end);
}
ll xu[402424];
int main() {
#ifdef cnyali_lk
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
  ll n, a, b;
  n = read();
  b = read();
  a = read();
  if ((a + b - 1) > n || (a * b < n))
    printf("-1\n");
  else {
    ll s = 0, t = n;
    while (s < n) {
      //			debug("Now%lld\n",s);
      if ((t - b) >= a - 1) {
        for (ll i = 1; i <= b; ++i) {
          xu[++s] = (t - b + i);
        }
        t -= b;
        --a;
      } else {
        for (ll i = 1; i <= t - a + 1; ++i)
          xu[++s] = t - (t - a + 1) + i;
        t = a - 1;
        while (t) {
          xu[++s] = t;
          --t;
        }
      }
    }
    for (ll i = 1; i <= n; ++i)
      printf("%lld%c", xu[i], i == n ? '\n' : ' ');
  }

  return 0;
}