Problem p03386 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

#define REP(i, num) for (int i = 0; i < (num); ++i)
#define ALL(c) c.begin(), c.end()
#define PRINTALL(c)                                                            \
  for (auto &x : c) {                                                          \
    cout << x << ' ';                                                          \
  }                                                                            \
  cout << endl;
#define PAIRCOMP(c, comp)                                                      \
  [](const pair<ll, ll> &lhs, const pair<ll, ll> &rhs) {                       \
    return lhs.c comp rhs.c;                                                   \
  }

constexpr int atcoder_mod = 1e9 + 7;

using namespace std;
using ll = long long;

template <typename T = int> T in() {
  T x;
  cin >> x;
  return (x);
}
template <typename T = int, typename C = vector<T>> C vecin(int N) {
  C x(N);
  REP(i, N) { x[i] = in(); }
  return move(x);
}

void vout() { cout << endl; }
template <typename Head, typename... Tail> void vout(Head &&h, Tail &&...t) {
  cout << ' ' << h;
  vout(forward<Tail>(t)...);
}
void out() { cout << endl; }
template <typename Head, typename... Tail> void out(Head &&h, Tail &&...t) {
  cout << h;
  vout(forward<Tail>(t)...);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int A = in(), B = in(), K = in();
  int N = B - A + 1;
  vector<int> V(N), T;
  iota(ALL(V), A);
  sort(ALL(V));
  REP(i, min(N, K)) T.push_back(V[i]);
  sort(ALL(V), greater<int>());
  REP(i, min(N, K)) T.push_back(V[i]);
  sort(ALL(T));
  T.erase(unique(ALL(T)), T.end());
  int M = T.size();
  REP(i, M) { out(T[i]); }

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define REP(i, num) for (int i = 0; i < (num); ++i)
#define ALL(c) c.begin(), c.end()
#define PRINTALL(c)                                                            \
  for (auto &x : c) {                                                          \
    cout << x << ' ';                                                          \
  }                                                                            \
  cout << endl;
#define PAIRCOMP(c, comp)                                                      \
  [](const pair<ll, ll> &lhs, const pair<ll, ll> &rhs) {                       \
    return lhs.c comp rhs.c;                                                   \
  }

constexpr int atcoder_mod = 1e9 + 7;

using namespace std;
using ll = long long;

template <typename T = int> T in() {
  T x;
  cin >> x;
  return (x);
}
template <typename T = int, typename C = vector<T>> C vecin(int N) {
  C x(N);
  REP(i, N) { x[i] = in(); }
  return move(x);
}

void vout() { cout << endl; }
template <typename Head, typename... Tail> void vout(Head &&h, Tail &&...t) {
  cout << ' ' << h;
  vout(forward<Tail>(t)...);
}
void out() { cout << endl; }
template <typename Head, typename... Tail> void out(Head &&h, Tail &&...t) {
  cout << h;
  vout(forward<Tail>(t)...);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int A = in(), B = in(), K = in();
  int N = B - A + 1;
  vector<int> T;
  for (int i = A; i < A + min(N, K); i++)
    T.push_back(i);
  for (int i = B; i > B - min(N, K); i--)
    T.push_back(i);
  sort(ALL(T));
  T.erase(unique(ALL(T)), T.end());
  int M = T.size();
  REP(i, M) { out(T[i]); }

  return 0;
}