Problem p02697 (C++)

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

#define int long long
#define uint unsigned int
#define ld long double
#define showoff                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a, int n) {
  a %= mod;
  if (n == 1)
    return a;
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
  return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;

int inverse(int x) {
  return power(x, mod - 2) % mod; // little fermat....
}

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n + 5);
  int i = 1, d = 1;
  while (m > 0) {
    while (used[i])
      ++i;
    cout << i << " " << i + d << "\n";
    used[i] = used[i + d] = 1;
    d++;
    m--;
  }
}

signed main() {
  showoff;
  int T = 1;
  // cin >> T;
  FOR(t, 1, T + 1) { solve(); }
  return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Fixed submission:
#include <bits/stdc++.h>

#define int long long
#define uint unsigned int
#define ld long double
#define showoff                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a, int n) {
  a %= mod;
  if (n == 1)
    return a;
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
  return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;

int inverse(int x) {
  return power(x, mod - 2) % mod; // little fermat....
}

void solve() {
  int n, m;
  cin >> n >> m;
  int i = 1;
  if (n % 2)
    while (m > 0) {
      cout << i << " " << n - i << "\n";
      i++;
      m--;
    }
  else {
    set<int> diff;
    int j = n;
    while (m > 0) {
      if (diff.find(j - i) == diff.end() && j - i != n / 2) {
        diff.insert(j - i);
        diff.insert(n - j + i);
        cout << i << " " << j << "\n";
        i++;
        j--;
        m--;
      } else
        j--;
    }
  }
}

signed main() {
  showoff;
  int T = 1;
  // cin >> T;
  FOR(t, 1, T + 1) { solve(); }
  return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...