Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 92 ms):
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <cstdlib>
#include <map>
#include <cmath>
#include <deque>

#define DEBUG if (deb)
#define f first
#define s second
#define pb push_back
#define forn(i, a, b) for (int i = int(a); i < int(b); i++)
#define LLINF 9223372036854775807
typedef long long int ll;
bool deb = false;
int mod = 1000000007;

using namespace std;

void dpInit(int n)
{
}

int log(int x)
{
    return 32 - __builtin_clz(x) - 1;
}
int log(ll x)
{
    return 64 - __builtin_clzll(x) - 1;
}
ll powMod(ll x, ll n, ll MOD)
{
    if (n == 0)
        return 1;
    ll ans = powMod(x, n / 2, MOD);

    if (n % 2 == 0)
    {
        return (ans * ans) % MOD;
    }
    else
    {
        return ((ans * ans) % MOD * x) % MOD;
    }
}

ll gcd(ll a, ll b)
{
    while (b)
    {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        string s;
        cin >> s;

        map<int, set<int>> m;
        vector<int> v;
        for (int x = 0; x < s.length(); x++)
        {
            int num = s[x] - '0';
            v.pb(num);
        }

        string ans;

        for (int i = 0; i < s.length(); i++)
        {
            int k = i;
            int j = 0;
            int maxVal = -1;
            int maxIdx = -1;
            DEBUG printf("at %i \n", i);
            while (k < s.length() && j <= 9)
            {
                DEBUG printf("Check %d\n", k);
                
                int val = v[k] - j;
                 DEBUG printf("v %d, val %d, delta %d\n", v[k], val, j);
                if (val > maxVal)
                {
                    maxVal = val;
                    maxIdx = k;
                }
                j++;
                k++;
            }
            
            for(int x = maxIdx - 1; x >=i; x--){
                int temp = v[x];
                v[x] = v[x+1];
                v[x+1] = temp;
            }

            ans.pb('0' + maxVal);
        }

        cout << ans << "\n";
    }
}

Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>

using namespace std;

#define ll            long long

#define TC(t)          int t; cin >> t; for(int i = 1; i <= t; i++)

#define pii            pair<int,int>

#define ft             ios::sync_with_stdio(false);  cin.tie(NULL);

#define endl             "\n"

#define pb             push_back

#define py             cout<<"YES\n";

#define pn             cout<<"NO\n";

#define vrev(v)        reverse(v.begin(),v.end());

#define vsort(v)       sort(v.begin(),v.end());

#define rsort(v)       sort(v.rbegin(),v.rend());

#define vlowerB(v,x)   lower_bound(v.begin(),v.end(),x)

#define vupperB(v,x)   upper_bound(v.begin(),v.end(),x)

#define F              first

#define S              second

#define rep(i,a,b)     for(int i=a;i<=b;i++)

#define rep2(i,b,a)    for(int i=b;i>=a;i--)

#define vi             vector<int>

#define zrbits(x)      __builtin_ctzll(x)

const int MOD=1e9+7;

void solve(){

    string s; cin>>s;

    int n=s.size();

    vi v;

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

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

    }

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

        int idx=i;

        int mx=0;

         for(int j=i;j<=min(n-1,i+9);j++){

            if(v[j]-(j-i)>=0 && v[j]-(j-i)>mx){

                mx=v[j]-(j-i);

                idx=j;

            }

         }

         while(idx>i){

            v[idx]--;

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

            idx--;

         }

    }

    for(int i:v) cout<<i;

    cout<<endl;

}

int32_t main()

{

   ft

   TC(t)

   solve(); 

    return 0;

}