Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
string num2bit(ll num, ll len) {
  string bit = "";
  REP(i, len) { bit += char('0' + (num >> i & 1)); }
  return bit;
}

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

  ll N, M;
  cin >> N >> M;

  ll K = (N - 1) / 2;

  vector<pll> res;

  ll s = 0, t = K;
  while (t > s) {
    res.push_back({s, t});
    t--;
    s++;
  }

  s = K + 1, t = 2 * K;
  while (t > s) {
    res.push_back({s, t});
    t--;
    s++;
  }

  REP(i, M) { cout << res[i].first + 1 << " " << res[i].second + 1 << endl; }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
string num2bit(ll num, ll len) {
  string bit = "";
  REP(i, len) { bit += char('0' + (num >> i & 1)); }
  return bit;
}

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

  ll N, M;
  cin >> N >> M;

  ll K = N;
  if (N % 2 == 1)
    K--;

  vector<pll> res;

  if (N % 2 == 0) {
    vector<bool> check(N, false);
    ll cnt = 0;
    REP(i, N) {
      if (!check[i]) {
        res.push_back({i + 1, i + cnt + 2});
        check[i] = true;
        check[i + cnt + 1] = true;
        cnt++;
        if (cnt >= M)
          break;
      }
    }
  } else {
    REP(i, M) { res.push_back({i + 1, K - i}); }
  }

  REP(i, M) { cout << res[i].first << " " << res[i].second << endl; }

  /*
  vector<ll> table(N, 0);
  REP(i, N){
      table[i] = i+1;
  }

  vector<pll> card(M);
  vector<vector<ll>> kati(N, vector<ll>(N, 0));
  REP(t, N){
      REP(j, M){
          card[j].first = 0;
          card[j].second = 0;
      }
      cout << table << endl;
      REP(i, N){
          REP(j, res.size()){
              if(res[j].first == table[i]) card[j].first = i+1;
              if(res[j].second== table[i]) card[j].second = i+1;
          }
      }
      cout << card << endl;
      REP(i, N){
          table[i] = (table[i]+1)%N;
          if(table[i]==0) table[i] = N;
      }

      REP(j, M){
          dump(card[j].second)
          dump(card[j].first)
          kati[t][card[j].first-1] = card[j].second;
          kati[t][card[j].second-1] = card[j].first;
      }
  }

  cout << kati << endl;
  */

  return 0;
}