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

Solution 1 (runtime: 46 ms):
// Look for parity
// check for what will happen to individual bit its participation
// check for pre computation

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define Y cout << "YES\n";
#define N cout << "NO\n";
#define all(v) (v).begin(), (v).end()
#define Sort(v) sort(all(v))
#define nl cout << "\n";

// DSU-------------------------------------------------------------------------------

// const int N = 1e6 + 10;
// int Parent[N];
// int size[N];

// void make(int v)
// {
//     Parent[v] = v;
//     size[v] = 1;
// }

// int find(int v)
// {
//     if (Parent[v] == v)
//         return v;

//     // Path Compression
//     return Parent[v] = find(Parent[v]);
// }

// void Union(int a, int b)
// {

//     a = find(a);
//     b = find(b);
//     // Optimzation using size
//     if (a != b)
//     {
//         if (size[a] < size[b])
//         {
//             swap(a, b);
//             Parent[b] = a;
//             size[a] += size[b];
//         }
//     }
// }

// -----------------------------------------------------------------------------------------

vector<int> printDivisors(int n)
{
    vector<int> v;

    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {

            if (n / i == i)
                v.push_back(i);

            else
            {
                v.push_back(i);
                v.push_back(n / i);
            }
        }
    }
    return v;
}

vector<int> getbinary(int x)
{
    vector<int> v;
    for (int i = 31; i >= 0; i--)
    {
        if (x & (1 << i))
            v.push_back(1);
        else
            v.push_back(0);
    }
    return v;
}

vector<int> primeFactors(int n)
{
    // Print the number of 2s that divide n
    vector<int> v;
    while (n % 2 == 0)
    {
        // cout << 2 << " ";
        v.push_back(2);
        n = n / 2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            // cout << i << " ";
            v.push_back(i);
            n = n / i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        v.push_back(n);

    return v;
}

void solve()
{

   string s;cin >> s;
  
   for (int i = 0; i < s.size(); i++)
   {
    int curr =s[i]-'0';
    int idx=i;
      for (int j = i+1; j < min((i+10),int(s.size())) ; j++)
      {
        if(s[j]=='0')continue;
            if((s[j]-'0')- (j-i) > curr){
                curr = (s[j]-'0') - (j-i);
                idx = j;
            }
      }

      for (int j = idx; j > i; j--)
      {
        swap(s[j],s[j-1]);
      }
      s[i]  -= ( idx-i);
      
      
   }

   cout << s <<"\n";
   
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    cin >> t;

    while (t--)
    {
        solve();
    }
}

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

using namespace std;

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
    os << '{';
    string sep;
    for (const T &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()

const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;

void solve()
{
    string s;
    cin >> s;
    vector<ll> v;
    for (int i = 0; i < s.length(); i++)
    {
        v.push_back(s[i] - '0');
    }
    for (int i = 1; i < s.length(); i++)
    {
        ll ind = i;
        while (ind >= 1 && v[ind] >= 1 && v[ind] > v[ind - 1]+1)
        {   
            swap(v[ind - 1], v[ind]);
            v[ind - 1]--;
            if (ind > 1)
                ind--;
            else
            {
                break;
            }
        }
    }
    string ans = "";
    for (int i = 0; i < v.size(); i++)
    {
        ans += (to_string(v[i]));
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc = 1;
    cin >> tc;
    while (tc--)
    {

        solve();
    }
}