Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int sum[105]; // sum[i] := 1~iまでの和
int cnt[105]; // cnt[i] := 頂点iに直接接続している頂点の数

void answer(vector<pii> ans) {
    cout << ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans.fst << ' ' << ans.scd << endl;
    }
}

signed main()
{
    for (int i = 1; i <= 104; ++i) sum[i] = sum[i - 1] + i;
    int N, K; cin >> N >> K;

    if (K < N - 2) {
        cout << -1 << endl;
        return 0;
    }

    if (N == 2) {
        if (K == 0) {
            cout << "1 2" << endl;
        } else {
            cout << "-1" << endl;
        }

        return 0;
    }

    // N >= 3
    for (int i = 3; i <= N; ++i) { // chainの数
        rep(i, 105) cnt[i] = 0;

        int k = 0;
        vector<pii> ans;
        for (int v = 1; v <= i - 1; ++v) {
            ans.PB(pii(v, v+1));
            cnt[v]++;
            cnt[v+1]++;
        }

        k += (i - 2);

        // 使った頂点の個数
        int used = i;
        // N - used == K - k となればあとははじっこに頂点を追加してくだけ
        // ↑これが目標
        for (int v = 2; v <= i - 1; ++v) {
            while (1) {
                k += cnt[v];
                used++;
                ans.PB(pii(v, used));

                if (N - used > K - k) {
                    k -= cnt[v];
                    used--;
                    ans.pop_back();
                    break;
                } 

                cnt[v]++;
                used++;
            }

            if (N - used == K - k) {
                rep(i, K - k) {
                    ans.PB(pii(1, used));
                    used++;
                }
                
                answer(ans);
                return 0;
            }
        }
    }

    cout << "aaaaaaa!!!!!!!\n";
}





Compiler output:
a.cc: In function 'void answer(std::vector<std::pair<int, int> >)':
a.cc:21:13: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
   21 | #define fst first
      |             ^~~~~
a.cc:57:21: note: in expansion of macro 'fst'
   57 |         cout << ans.fst << ' ' << ans.scd << endl;
      |                     ^~~
a.cc:22:13: error: 'class std::vector<std::pair<int, int> >' has no member named 'second'
   22 | #define scd second
      |             ^~~~~~
a.cc:57:39: note: in expansion of macro 'scd'
   57 |         cout << ans.fst << ' ' << ans.scd << endl;
      |                                       ^~~