Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fori(i, a, b) for(int i = a; i < b; ++i)
#define rfori(i, a, b) for(int i = a; i >= b; --i)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define clr(a) memset(a, 0, sizeof(a))
#define set_mem(a, b) memset(a, b, sizeof(a))
#define sz(v) (int)v.size()
#define umap unordered_map
#define uset unordered_set
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pq priority_queue
#define minpq(x) priority_queue<x, vector<x>, greater<x>>

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

void solve()
{
    string s;
    cin >> s;
    ll n = s.length();

    for (ll i = 0; i < n; i++) {
        string temp = s;
        ll maxi = LONG_MIN;
        ll idx = i;
        
     
        for (ll j = i + 1; j < n; j++) {
            if ((s[j] - '0'-(j-i)) > maxi-(idx-i) && idx>=0) {
                maxi = s[j] - '0'; 
                idx = j;   
            }
        }

   
        if (maxi - (idx-i)> (s[i] - '0')) {
            
            char maxChar = s[idx]-(idx-i);
            for (ll j = idx; j > i; j--) {
                s[j] = s[j - 1];
            }
            s[i] = maxChar;
        }
    }

    cout << s << endl;
    



























    // ll maxi = INT_MIN;
    // int cnt = 1;
    // vector<pair<int,int>> maxArr(n,{-1,cnt});

    // for(int i=n-1;i>=0;i--){
    //     if(maxi == s[i]-'0') cnt++;
    //     if(s[i]-'0'>maxi) maxi = s[i]-'0';
        
    //     maxArr[i].f = max(s[i]-'0',maxi);
    //     maxArr[i].s = cnt;
    // }
    // for(auto it:maxArr){
    //     cout<<it.f<<","<<it.s<<" ";

    // }
    // cout<<endl;
}

int main() {
    fast_io;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fori(i, a, b) for(int i = a; i < b; ++i)
#define rfori(i, a, b) for(int i = a; i >= b; --i)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define clr(a) memset(a, 0, sizeof(a))
#define set_mem(a, b) memset(a, b, sizeof(a))
#define sz(v) (int)v.size()
#define umap unordered_map
#define uset unordered_set
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pq priority_queue
#define minpq(x) priority_queue<x, vector<x>, greater<x>>

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

void solve()
{
    string s;
    cin >> s;
    ll n = s.length();


    for(ll i=1;i<n;i++){
        for(ll j=i;j>0;j--){
            if(s[j]-1>s[j-1]){
                swap(--s[j],s[j-1]);
            }
            else break;
        }
    }
    cout<<s<<endl;
    // string s;
    // cin >> s;
    // ll n = s.length();

    // for (ll i = 0; i < n; i++) {
    //     string temp = s;
    //     ll maxi = LONG_MIN;
    //     ll idx = i;
        
     
    //     for (ll j = i + 1; j < n; j++) {
    //         if ((s[j] - '0'-(j-i)) > maxi-(idx-i) && idx>=0) {
    //             maxi = s[j] - '0'; 
    //             idx = j;   
    //         }
    //     }

   
    //     if (maxi - (idx-i)> (s[i] - '0')) {
            
    //         char maxChar = s[idx]-(idx-i);
    //         for (ll j = idx; j > i; j--) {
    //             s[j] = s[j - 1];
    //         }
    //         s[i] = maxChar;
    //     }
    // }

    // cout << s << endl;
    



























    // ll maxi = INT_MIN;
    // int cnt = 1;
    // vector<pair<int,int>> maxArr(n,{-1,cnt});

    // for(int i=n-1;i>=0;i--){
    //     if(maxi == s[i]-'0') cnt++;
    //     if(s[i]-'0'>maxi) maxi = s[i]-'0';
        
    //     maxArr[i].f = max(s[i]-'0',maxi);
    //     maxArr[i].s = cnt;
    // }
    // for(auto it:maxArr){
    //     cout<<it.f<<","<<it.s<<" ";

    // }
    // cout<<endl;
}

int main() {
    fast_io;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}