Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////
 
 
int main() {
	int n, k; cin >> n >> k;
	int ma = (n - 1)*(n - 2) / 2;
	if (ma < k)cout << -1 << endl;
	else {
		vector<pii>res;
		for (int i = 1; i <= n - 1; ++i) {
			res.push_back({ i,n });
		}
		int rem = ma - k;
		int ci = 1, cj = 2;
		for (int i = 0; i < rem; ++i) {
			res.push_back({ ci,cj });
			++cj;
			if (cj == n) {
				++ci;
				cj = ci + 1;
			}
		}
		cout << res.size() << endl;
		for (auto p : res) {
			cout << p.first << " " << p.second << endl;
		}
	}
	return 0;
}
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


int main() {
	int n, k; cin >> n >> k;
	int ma = (n - 1)*(n - 2) / 2;
	if (ma < k)cout << -1 << endl;
	else {
		vector<pii>res;
		for (int i = 1; i <= n - 1; ++i) {
			res.push_back({ i,n });
		}
		int rem = ma - k;
		int ci = 1, cj = 2;
		for (int i = 0; i < rem; ++i) {
			res.push_back({ ci,cj });
			++cj;
			if (cj == n) {
				++ci;
				cj = ci + 1;
			}
		}
		cout << res.size() << endl;
		for (auto p : res) {
			cout << p.first << " " << p.second << endl;
		}
	}
	return 0;
}


Compiler output:
a.cc:106:10: error: redefinition of 'const ll dx [4]'
  106 | const ll dx[4] = { 0,1,0,-1 };
      |          ^~
a.cc:29:10: note: 'const ll dx [4]' previously defined here
   29 | const ll dx[4] = { 0,1,0,-1 };
      |          ^~
a.cc:107:10: error: redefinition of 'const ll dy [4]'
  107 | const ll dy[4] = { -1, 0, 1,0 };
      |          ^~
a.cc:30:10: note: 'const ll dy [4]' previously defined here
   30 | const ll dy[4] = { -1, 0, 1,0 };
      |          ^~
a.cc:108:11: error: redefinition of 'const int INF'
  108 | const int INF = 1e9 + 7;
      |           ^~~
a.cc:31:11: note: 'const int INF' previously defined here
   31 | const int INF = 1e9 + 7;
      |           ^~~
a.cc:109:5: error: redefinition of 'int gcd(int, int)'
  109 | int gcd(int x, int y) {
      |     ^~~
a.cc:32:5: note: 'int gcd(int, int)' previously defined here
   32 | int gcd(int x, int y) {
      |     ^~~
a.cc:114:6: error: redefinition of 'void mul(ll, ll)'
  114 | void mul(ll a, ll b) {
      |      ^~~
a.cc:37:6: note: 'void mul(ll, ll)' previously defined here
   37 | void mul(ll a, ll b) {
      |      ^~~
a.cc:117:8: error: redefinition of 'double mysqrt(double)'
  117 | double mysqrt(double x) {
      |        ^~~~~~
a.cc:40:8: note: 'double mysqrt(double)' previously defined here
   40 | double mysqrt(double x) {
      |        ^~~~~~
a.cc:129:5: error: redefinition of 'int main()'
  129 | int main() {
      |     ^~~~
a.cc:52:5: note: 'int main()' previously defined here
   52 | int main() {
      |     ^~~~