Problem p03421 (C++)

Buggy submission (status: Runtime Error):
// #define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
static constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_same<T, std::string>::value>::type {
  d = std::string();
  int c = 0;
  while (c < 'a' || 'z' < c)
    c = fgetc(stdin);
  while ('a' <= c && c <= 'z') {
    d.push_back(c);
    c = fgetc(stdin);
  }
}
template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_same<T, double>::value>::type {
  scanf("%lf", &d);
}
template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_signed<T>::value ==
                            std::is_same<T, std::string>::value>::type {
  d = 0;
  int c = 0;
  while (c < '0' || '9' < c)
    c = fgetc(stdin);
  while ('0' <= c && c <= '9') {
    d = d * 10 + c - '0';
    c = fgetc(stdin);
  }
}
template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_signed<T>::value !=
                            std::is_same<T, double>::value>::type {
  d = 0;
  int c = 0;
  bool f = 0;
  while (c < '0' || '9' < c) {
    if (c == '-')
      f = 1;
    c = fgetc(stdin);
  }
  while ('0' <= c && c <= '9') {
    d = d * 10 + c - '0';
    c = fgetc(stdin);
  }
  if (f)
    d = -d;
}

int main(void) {
  uint32 n, a, b;
  scan(n);
  scan(a);
  scan(b);
  if (n + 1 < a + b) {
    puts("-1");
    return 0;
  }
  if (n + 1 == a + b) {
    printf("%u", b);
    for (uint32 i = b - 1; i; --i) {
      printf(" %u", i);
    }
    for (uint32 i = b + 1; i <= n; ++i) {
      printf(" %u", i);
    }
    printf("\n");
    return 0;
  }
  if (a * b < n) {
    puts("-1");
    return 0;
  }
  abort();
  return 0;
}

Fixed submission:
// #define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
static constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_same<T, std::string>::value>::type {
  d = std::string();
  int c = 0;
  while (c < 'a' || 'z' < c)
    c = fgetc(stdin);
  while ('a' <= c && c <= 'z') {
    d.push_back(c);
    c = fgetc(stdin);
  }
}
template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_same<T, double>::value>::type {
  scanf("%lf", &d);
}
template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_signed<T>::value ==
                            std::is_same<T, std::string>::value>::type {
  d = 0;
  int c = 0;
  while (c < '0' || '9' < c)
    c = fgetc(stdin);
  while ('0' <= c && c <= '9') {
    d = d * 10 + c - '0';
    c = fgetc(stdin);
  }
}
template <typename T>
auto scan(T &d) ->
    typename std::enable_if<std::is_signed<T>::value !=
                            std::is_same<T, double>::value>::type {
  d = 0;
  int c = 0;
  bool f = 0;
  while (c < '0' || '9' < c) {
    if (c == '-')
      f = 1;
    c = fgetc(stdin);
  }
  while ('0' <= c && c <= '9') {
    d = d * 10 + c - '0';
    c = fgetc(stdin);
  }
  if (f)
    d = -d;
}

int main(void) {
  uint32 n, a, b;
  scan(n);
  scan(a);
  scan(b);
  if (n + 1 < a + b) {
    puts("-1");
    return 0;
  }
  if (n + 1 == a + b) {
    printf("%u", b);
    for (uint32 i = b - 1; i; --i) {
      printf(" %u", i);
    }
    for (uint32 i = b + 1; i <= n; ++i) {
      printf(" %u", i);
    }
    printf("\n");
    return 0;
  }
  if (a * b < n) {
    puts("-1");
    return 0;
  }
  uint32 m = n;
  m -= b;
  m -= a - 1;
  uint32 fb = m / (b - 1);
  uint32 d = m % (b - 1);
  std::vector<uint32> ans(n);
  uint32 itr = 0;
  for (uint32 i = 0; i < b; ++i) {
    ans[itr++] = b - i;
  }
  for (uint32 i = 1; i <= fb; ++i) {
    for (uint32 j = 0; j < b; ++j) {
      ans[itr++] = (i + 1) * b - j;
    }
  }
  if (d != 0) {
    for (uint32 i = 0; i <= d; ++i) {
      ans[itr++] = (fb + 1) * b + (d + 1 - i);
    }
  }
  uint32 pitr = itr;
  while (itr < n) {
    ans[itr] = itr + 1;
    ++itr;
  }
  printf("%u", ans[0]);
  for (uint32 i = 1; i < n; ++i) {
    printf(" %u", ans[i]);
  }
  printf("\n");
  return 0;
}