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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    REP(WW, n) cerr << v[WW] << ' ';                                           \\
    cerr << endl;                                                              \\
  }
#define SHOW2d(v, WW, HH)                                                      \\
  {                                                                            \\
    REP(W_, WW) {                                                              \\
      REP(H_, HH) cerr << v[W_][H_] << ' ';                                    \\
      cerr << endl;                                                            \\
    }                                                                          \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll, ll> P;

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

  ll n, m;
  cin >> n >> m;
  vector<bool> used(222222);

  ll now = n - 1;
  for (ll i = 1; i <= m; i++) {
    if (!used[now] && !used[n - now] && now != n - now) {
      used[n - now] = true;
      used[now] = true;
      cout << i << " " << i + now << endl;
    } else {
      now--;
      used[n - now] = true;
      used[now] = true;
      cout << i << " " << i + now << endl;
    }
    // cout << "now " << now << " " << n-now << endl;
    now -= 2;
    // SHOW1d(used, 10);
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    REP(WW, n) cerr << v[WW] << ' ';                                           \\
    cerr << endl;                                                              \\
  }
#define SHOW2d(v, WW, HH)                                                      \\
  {                                                                            \\
    REP(W_, WW) {                                                              \\
      REP(H_, HH) cerr << v[W_][H_] << ' ';                                    \\
      cerr << endl;                                                            \\
    }                                                                          \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll, ll> P;

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

  ll n, m;
  cin >> n >> m;
  vector<bool> used(111111);

  ll now = n - 1;
  for (ll i = 1; i <= m; i++) {
    if (!used[now] && !used[n - now] && now != n - now) {
      used[n - now] = true;
      used[now] = true;
      cout << i << " " << i + now << endl;
    } else {
      now--;
      used[n - now] = true;
      used[now] = true;
      cout << i << " " << i + now << endl;
    }
    // cout << "now " << now << " " << n-now << endl;
    now -= 2;
    // SHOW1d(used, 10);
  }

  return 0;
}