Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

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



#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key



#define ll long long

#define gap " "

#define nline "\n"

#define pi 2 * acos(0.0)

#define yes cout<<"YES\n"

#define no cout<<"NO\n"

#define bigger greater<int>()



const int inf = INT_MAX;

const int mod = 1e9 + 7;



#ifndef ONLINE_JUDGE

#include "template.cpp"

#else

#define debug(...)

#define debugArr(...)

#endif









signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



    int testCases;

    cin >> testCases;

    while (testCases--){

        string s;

        cin>>s;



        vector<int> v;



        for(int i=0;i<s.size();i++){

            v.push_back(s[i]-'0');

        }



        for(int i=0;i<v.size();i++){

            if(v[i]==0) continue;

            priority_queue<pair<int, int>> pq;

            pq.push({v[i], i});



            for(int j=i+1;j<v.size();j++){

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

                    continue;

                }else{

                    pq.push({v[j]-j+i, j});

                }

            }

            debug(pq);

            int val = pq.top().first;

            int pos = pq.top().second;



            while(!pq.empty()){

                if(pq.top().first==val){

                    pos = pq.top().second;

                    pq.pop();

                }else{

                    break;

                }

            }

            

            for(int j=pos; j>i; j--){

                v[j] = v[j-1];

            }

            v[i] = val;

        }



        for(int i: v){

            cout<<i;

        }

        cout<<nline;

    }

}

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>



#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key



#define ll long long

#define gap " "

#define nline "\n"

#define pi 2 * acos(0.0)

#define yes cout<<"YES\n"

#define no cout<<"NO\n"

#define bigger greater<int>()



const int inf = INT_MAX;

const int mod = 1e9 + 7;



#ifndef ONLINE_JUDGE

#include "template.cpp"

#else

#define debug(...)

#define debugArr(...)

#endif









signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



    int testCases;

    cin >> testCases;

    while (testCases--){

        string s;

        cin>>s;



        vector<int> v;



        for(int i=0;i<s.size();i++){

            v.push_back(s[i]-'0');

        }



        for(int i=0;i<v.size();i++){

            priority_queue<pair<int, int>> pq;

            pq.push({v[i], i});



            for(int j=i+1;j<v.size();j++){

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

                    continue;

                }else{

                    pq.push({v[j]-j+i, j});

                }

            }

            debug(pq);

            int val = pq.top().first;

            int pos = pq.top().second;



            while(!pq.empty()){

                if(pq.top().first==val){

                    pos = pq.top().second;

                    pq.pop();

                }else{

                    break;

                }

            }

            

            for(int j=pos; j>i; j--){

                v[j] = v[j-1];

            }

            v[i] = val;

        }



        for(int i: v){

            cout<<i;

        }

        cout<<nline;

    }

}