Language: C++

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<random>
#include<fstream>
#include<iterator>
#include <numeric>

using namespace std;


vector<int>x;
vector<int>y;


int main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int N = 0;

	int n = 0;


	cin >> N;

	vector<int>a(N);

	vector<int > not(N, 0);

	vector<int>b(N);

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	int cnt = 0;

	while (1) {
		iota(b.begin(), b.end(), 0);

		sort(b.begin(), b.end(), [&](int x, int y) {return a[x] < a[y]; });
		cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			if (a[i] > a[i + 1]) {
				cnt++;
				not[i] = 1;
			}
			else {
				not[i] = 0;
			}
		}

		//for (int i = 0; i < N; i++) {
		//	cout << a[i] << " ";
		//
		//}
		//cout << endl;


		if (cnt == 0)
			break;


		for (int i = 0; i < N - 1; i++) {
			if (not[i] == 1) {
				for (int j = 0; j < N; j++) {
					if (a[i] + a[b[j]] <= a[i + 1]) {
						n++;
						x.push_back(b[j] + 1);
						y.push_back(i + 1);
						a[i] += a[b[j]];
						break;

					}
					else if (a[i] <= a[i + 1] + a[b[i]]) {
						n++;
						x.push_back(b[j] + 1);
						y.push_back(i + 2);
						a[i + 1] += a[b[j]];
						break;

					}
					else {
						n++;
						a[i + 1] += a[b[N - 1]];
						x.push_back(b[N - 1] + 1);
						y.push_back(i + 2);
						break;

					}
				}
				break;

			}
		}

	}

	cout << n << endl;

	for (int i = 0; i < n; i++) {
		cout << x[i] << " " << y[i] << endl;
	}

	//getchar();
	//getchar();

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:22: error: expected unqualified-id before 'not' token
   34 |         vector<int > not(N, 0);
      |                      ^~~
a.cc: In lambda function:
a.cc:52:40: error: expected '{' before '=' token
   52 |                                 not[i] = 1;
      |                                        ^
a.cc: In function 'int main()':
a.cc:52:33: error: no match for 'operator!' (operand type is 'main()::<lambda()>')
   52 |                                 not[i] = 1;
      |                                 ^~~~~~
a.cc:52:33: note: candidate: 'operator!(bool)' (built-in)
a.cc:52:33: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'bool'
a.cc: In lambda function:
a.cc:55:40: error: expected '{' before '=' token
   55 |                                 not[i] = 0;
      |                                        ^
a.cc: In function 'int main()':
a.cc:55:33: error: no match for 'operator!' (operand type is 'main()::<lambda()>')
   55 |                                 not[i] = 0;
      |                                 ^~~~~~
a.cc:55:33: note: candidate: 'operator!(bool)' (built-in)
a.cc:55:33: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'bool'
a.cc: In lambda function:
a.cc:71:36: error: expected '{' before '==' token
   71 |                         if (not[i] == 1) {
      |                                    ^~
a.cc: In function 'int main()':
a.cc:71:29: error: no match for 'operator!' (operand type is 'main()::<lambda()>')
   71 |                         if (not[i] == 1) {
      |                             ^~~~~~
a.cc:71:29: note: candidate: 'operator!(bool)' (built-in)
a.cc:71:29: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'bool'