Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int Max_n = 54;
long long a[Max_n], ans_arr[Max_n][2], ans=0;
vector<pair<int, int> > pairs(Max_n);
    
int main(){
    int N, ans=0;
    cin >> N;
    int min = pairs[0].first;
    int min_idx = pairs[0].second;
    int max = pairs[N-1].first;
    int max_idx = pairs[N-1].second;
    

    for(int i =0; i < N; i++){
        cin >> a[i];
        pairs[i] = make_pair(a[i], i);
    }
    stable_sort(pairs.begin(), pairs.begin() + N);
    
    //if(a[i-1] <= a[i]) //次に進む
    //if(min < a[i]) //もう一度最小値をたす
    //if(a[i-1] > a[i]) //最小値ををたす a[i] + min
    int min = pairs[0].first;
    int min_idx = pairs[0].second;
    int max = pairs[N-1].first;
    int max_idx = pairs[N-1].second;
    
    if(abs(max) < abs(min)){
        for(int i =N-1; i > 0; i--){
            if(a[i-1] > a[i]){
                a[i-1] += min;
                ans_arr[ans][0] = i -1;
                ans_arr[ans][1] = min_idx;
                ans++;

                if(min > a[i-1]){
                    min = a[i-1];
                    min_idx = i -1;
                }

                if(a[i-1] > a[i]){
                    a[i-1] += min;
                    ans_arr[ans][0] = i - 1;
                    ans_arr[ans][1] = min_idx;
                    ans++;
                }

                if(min > a[i-1]){
                    min = a[i-1];
                    min_idx = i -1;
                }
            }
        }
    }
    else{
        for(int i =1; i < N; i++){
            if(a[i-1] > a[i]){
                a[i] += max;
               

                ans_arr[ans][0] = i;
                ans_arr[ans][1] = max_idx;
                ans++;
                

                if(max < a[i]){
                    max = a[i];
                    max_idx = i;
                }

                if(a[i-1] > a[i]){
                    a[i] += max;

                    ans_arr[ans][0] = i;
                    ans_arr[ans][1] = max_idx;
                    ans++;
                    }

                if(max < a[i]){
                    max = a[i];
                    max_idx = i;
                }
            }
        }

    }
    cout << ans << endl;
    for(int i =0; i < ans; i++){
        cout << ans_arr[i][1] + 1<< " " << ans_arr[i][0] +1  << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:9: error: redeclaration of 'int min'
   28 |     int min = pairs[0].first;
      |         ^~~
a.cc:13:9: note: 'int min' previously declared here
   13 |     int min = pairs[0].first;
      |         ^~~
a.cc:29:9: error: redeclaration of 'int min_idx'
   29 |     int min_idx = pairs[0].second;
      |         ^~~~~~~
a.cc:14:9: note: 'int min_idx' previously declared here
   14 |     int min_idx = pairs[0].second;
      |         ^~~~~~~
a.cc:30:9: error: redeclaration of 'int max'
   30 |     int max = pairs[N-1].first;
      |         ^~~
a.cc:15:9: note: 'int max' previously declared here
   15 |     int max = pairs[N-1].first;
      |         ^~~
a.cc:31:9: error: redeclaration of 'int max_idx'
   31 |     int max_idx = pairs[N-1].second;
      |         ^~~~~~~
a.cc:16:9: note: 'int max_idx' previously declared here
   16 |     int max_idx = pairs[N-1].second;
      |         ^~~~~~~