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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
// #define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
/*
int main(void){
    ll n,m,q;
    cin>>n>>m>>q;
    vvl quer(q,vl(4));
    rep(i,q){
        cin>>quer[i][0]>>quer[i][1]>>quer[i][2]>>quer[i][3];
    }
    rep(i,(1<<n)){
        vl pitsu(n,-);
        rep(j,n){
            if(i&(1<<j) == 1){
                ll now = pitsu[quer[j][1]-1]-pitsu[quer[j][0]-1];
                if(now == pitsu[quer[j][2]]) continue;
                else if(now < pitsu[quer[j][2]])
            }
        }
    }
}
*/

int main(void) {
  ll n, m;
  cin >> n >> m;
  vb a(n, false);
  ll cnt = 0;
  ll hue = 1;
  if (m % 2 == 0) {
    rep(i, m / 2) { cout << i + 1 << " " << m - i + 1 << endl; }
    rep(i, m / 2) { cout << m + 1 + i + 1 << " " << 2 * m - i + 1 << endl; }
  } else {
    rep(i, m / 2 + 1) { cout << i + 1 << " " << m + 1 - i << endl; }
    rep(i, m / 2) { cout << i + m + 2 << " " << 2 * m + 1 - i << endl; }
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
#define mrep(i, n) for (ll i = n; i >= 0; --i)
#define all(a) (a).begin(), (a).end()
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pl pair<ll, ll>
#define inf 1001001001001001000
// #define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
/*
int main(void){
    ll n,m,q;
    cin>>n>>m>>q;
    vvl quer(q,vl(4));
    rep(i,q){
        cin>>quer[i][0]>>quer[i][1]>>quer[i][2]>>quer[i][3];
    }
    rep(i,(1<<n)){
        vl pitsu(n,-);
        rep(j,n){
            if(i&(1<<j) == 1){
                ll now = pitsu[quer[j][1]-1]-pitsu[quer[j][0]-1];
                if(now == pitsu[quer[j][2]]) continue;
                else if(now < pitsu[quer[j][2]])
            }
        }
    }
}
*/

int main(void) {
  ll n, m;
  cin >> n >> m;
  vb a(n, false);
  ll cnt = 0;
  ll hue = 1;
  rep(i, n) {
    if (a[i] == false) {
      a[i] = true;
      a[i + hue] = true;
      cout << i + 1 << " " << i + hue + 1 << endl;
      cnt++;
      hue++;
      if (cnt == m)
        break;
    }
  }
}