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

Code 1:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
//#define node pair< ll , pair<int , int > >



ll mod = 1000000007 , sz = 1e6 + 10;
bool sortBF(pair<int,int> a , pair<int,int> b){return a.first>b.first;}
bool sortdec(ll a,ll b){return a >= b ;}

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

int lg (ll x){
    return __builtin_clzll(1) - __builtin_clzll(x);
}

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

ll fPower(ll x, ll y)
{
     x %= mod;
     y %= mod;
     ll res = 1;
     while (y > 0) {
         if (y % 2 == 1)
            res = (res * x)%mod;
         y = y >> 1;
         x = (x * x);
         x %= mod;
    }
    return (res%mod);
}

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



int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(0);
    //freopen("tictactoe.in" , "r" , stdin);
    //freopen("output.txt" , "w" , stdout);
    int tt = 1 , tc = 1;
    cin>>tt;
    while(tt--){
        string s;cin>>s;
        int n = s.size();
        int arr[n];
        for (int i = 0 ; i < n ; i++)arr[i] = (s[i] - '0');
        set<int>idx;
        for (int i = 0 ; i < min(9 , n) ; i++)idx.insert(i);
        int ans [n];
        for (int i = 0 ; i < n ; i++){
            int j = 0 , bestIdx = 0 , bestVal = -1;
            for (auto v : idx){
                if (arr[v] - j > bestVal){
                    bestVal = arr[v] - j;
                    bestIdx = v;
                }
                j++;
            }
            idx.erase(bestIdx);
            ans[i] = bestVal;
            if (i + 9 < n)idx.insert(i + 9);
        }
        for (auto i : ans)cout<<i;
        cout<<'\n';
    }
}




///nCr method
/*
vector <vector<ll>>memo(1001 , vector<ll>(1001 , -1));

ll nCr(ll n, ll r){
    if (r > n)
        return 0;
    if (r == 0 || r == n)
        return 1;
    if (memo[n][r] > -1)return memo[n][r];
    memo[n][r] = nCr(n - 1, r - 1) + nCr(n - 1, r);
    return memo[n][r];
}
*/


Code 2:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
//#define node pair< ll , pair<int , int > >



ll mod = 1000000007 , sz = 1e6 + 10;
bool sortBF(pair<int,int> a , pair<int,int> b){return a.first>b.first;}
bool sortdec(ll a,ll b){return a >= b ;}

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

int lg (ll x){
    return __builtin_clzll(1) - __builtin_clzll(x);
}

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

ll fPower(ll x, ll y)
{
     x %= mod;
     y %= mod;
     ll res = 1;
     while (y > 0) {
         if (y % 2 == 1)
            res = (res * x)%mod;
         y = y >> 1;
         x = (x * x);
         x %= mod;
    }
    return (res%mod);
}

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



int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(0);
    //freopen("tictactoe.in" , "r" , stdin);
    //freopen("output.txt" , "w" , stdout);
    int tt = 1 , tc = 1;
    cin>>tt;
    while(tt--){
        string s;cin>>s;
        int n = s.size();
        int arr[n];
        for (int i = 0 ; i < n ; i++)arr[i] = (s[i] - '0');
        set<int>idx;
        for (int i = 0 ; i < min(9 , n) ; i++)idx.insert(i);
        int ans [n];
        for (int i = 0 ; i < n ; i++){
            int j = 0 , bestIdx = 0 , bestVal = 0;
            for (auto v : idx){
                if (arr[v] - j > bestVal){
                    bestVal = arr[v] - j;
                    bestIdx = v;
                }
                j++;
            }
            idx.erase(bestIdx);
            ans[i] = bestVal;
            if (i + 9 < n)idx.insert(i + 9);
        }
        for (auto i : ans)cout<<i;
        cout<<'\n';
    }
}




///nCr method
/*
vector <vector<ll>>memo(1001 , vector<ll>(1001 , -1));

ll nCr(ll n, ll r){
    if (r > n)
        return 0;
    if (r == 0 || r == n)
        return 1;
    if (memo[n][r] > -1)return memo[n][r];
    memo[n][r] = nCr(n - 1, r - 1) + nCr(n - 1, r);
    return memo[n][r];
}
*/


Answer: 1