Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

#define int long long int



// Function to check if `b` is present in `mat[a]` using binary search

bool present(int a, int b, const vector<vector<int>>& mat) {

    if (a > 1000 || a < 0 || mat[a].empty()) return false;

    return binary_search(mat[a].begin(), mat[a].end(), b);

}



signed main() {

    int t;

    t = 3;

    while (t--) {

        int n;

        cin >> n;

        vector<int>arr(n,0);

        for (int i = 0; i < n; i++) {

            cin >> arr[i];

        }



        

        int ind = 1e9;

        map<int, int> mp;

        vector<pair<int, int>> ans;

        vector<vector<int>> mat(1001);



       for(int i=0;i<n;i++){

           vector<int>l;

           for(int j=i+1;j<n;j++){

               if(arr[j]<arr[i]){

                   mat[arr[i]].push_back(arr[j]);

                   l.push_back(arr[j]);

               }

           }

          sort(l.begin(),l.end());

          reverse(l.begin(),l.end());

           for(int x:l){

               ans.push_back({arr[i],x});

           }

       }



        //    cout<<" value of i"<<i<<endl;

        //    for(int ele:mat[i]){

        //        cout<<ele<<" ";

        ////    }

//cout<<endl;

      //  }

      vector<pair<int,int>>result1;

         for(int i=0;i<n;i++){

             for(int j=i-1;j>=0;j--){

                 if(arr[j]<arr[j+1]){

                     result1.push_back({arr[j+1],arr[j]});

                     swap(arr[j+1],arr[j]);

                 }

             }

         }

         

        cout << ans.size()+result1.size()*2 << endl;

        for (auto p : ans) {

            cout << p.first << " " << p.second << endl;

        }

        for(auto p:result1){

            cout<<p.first<<" "<<p.second<<endl;

        }reverse(result1.begin(),result1.end());

        for(auto p:result1){

            cout<<p.second<<" "<<p.first<<endl;

        }

    }

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

#define int long long int



// Function to check if `b` is present in `mat[a]` using binary search

bool present(int a, int b, const vector<vector<int>>& mat) {

    if (a > 1000 || a < 0 || mat[a].empty()) return false;

    return binary_search(mat[a].begin(), mat[a].end(), b);

}



signed main() {

    int t;

    t = 1;

    while (t--) {

        int n;

        cin >> n;

        vector<int>arr(n,0);

        for (int i = 0; i < n; i++) {

            cin >> arr[i];

        }



        

        int ind = 1e9;

        map<int, int> mp;

        vector<pair<int, int>> ans;

        vector<vector<int>> mat(1001);



       for(int i=0;i<n;i++){

           vector<int>l;

           for(int j=i+1;j<n;j++){

               if(arr[j]<arr[i]){

                   mat[arr[i]].push_back(arr[j]);

                   l.push_back(arr[j]);

               }

           }

          sort(l.begin(),l.end());

          reverse(l.begin(),l.end());

           for(int x:l){

               ans.push_back({arr[i],x});

           }

       }



        //    cout<<" value of i"<<i<<endl;

        //    for(int ele:mat[i]){

        //        cout<<ele<<" ";

        ////    }

//cout<<endl;

      //  }

      vector<pair<int,int>>result1;

         for(int i=0;i<n;i++){

             for(int j=i-1;j>=0;j--){

                 if(arr[j]<arr[j+1]){

                     result1.push_back({arr[j+1],arr[j]});

                     swap(arr[j+1],arr[j]);

                 }

             }

         }

         

        cout << ans.size()+result1.size()*2 << endl;

        for (auto p : ans) {

            cout << p.first << " " << p.second << endl;

        }

        for(auto p:result1){

            cout<<p.first<<" "<<p.second<<endl;

        }reverse(result1.begin(),result1.end());

        for(auto p:result1){

            cout<<p.second<<" "<<p.first<<endl;

        }

    }

}