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

Previous submission (verdict: Wrong answer on test 3):
#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++){

            int val = v[i];

            int pos = i;



            for(int j=i; j< min(val+10, (int) v.size());j++){

                if(v[j]-j+i > val){

                    val = v[j]-j+i;

                    pos = j;

                }

            }



            while(pos > i){

                swap(v[pos], v[pos-1]);

                pos--;

            }

            v[i] = val;

        }



        for(int i: v){

            cout<<i;

        }

        cout<<nline;

    }

}

Submission (verdict: Accepted):
#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++){

            int val = v[i];

            int pos = i;



            for(int j=i; j< min(i+10, (int) v.size());j++){

                if(v[j]-j+i > val){

                    val = v[j]-j+i;

                    pos = j;

                }

            }



            while(pos > i){

                swap(v[pos], v[pos-1]);

                pos--;

            }

            v[i] = val;

        }



        for(int i: v){

            cout<<i;

        }

        cout<<nline;

    }

}