Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <cstdio>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define nl cout<<endl
#define vec vector<int>
#define vecs vector<string>
#define ddv vector<vec>
#define ub upper_bound 
#define lb lower_bound
#define prnt(v) for(auto i:v) cout<<i<<" "; nl
#define inp(v); for(auto &i:v) cin>>i;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int N = 2e5;
const int M = 1e9+7;

int factorials[N+1];
int factInv[N+1];
bool isPrime[N+1];

int gcd(int a,int b){ //O(logb)
    if(!b) return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){ //O(logb)
    return (a*b/gcd(a,b)) % M;
}

int binExp(long long a, int b) { //O(logb)
    a %= M;
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * 1LL * a) % M;
        a = (a * 1LL * a) % M;
        b >>= 1;
    }
    return ans;
}

int inv(int n){ //O(logM)
    return binExp(n,M-2);
}

void FACT(){ //O(N)
    factorials[0] = 1;
    for (int i = 1; i <= N; i++) {
        factorials[i] = factorials[i - 1] * 1LL * i % M;
    }
}

void FACTINV(){ //O(N)
    for (int i = 0; i <= N; i++) {
        factInv[i] = inv(factorials[i]);
    }
}

void SIEVE(){ //O(NloglogN)

    //Pre-compute

    fill(isPrime, isPrime+N, true);
    isPrime[0]=isPrime[1]=false;

    for(int i = 2; i <= N; ++i){
        if(isPrime[i]){
            for(int j=2*i ; j<=N ; j+=i)
                isPrime[j]=false;
        }
    }
}

long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N).

    // Pre-Compute before using this func.
    // FACT();
    // FACTINV();

    if (r > n) return 0;
    return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M;
}

void solve(){
    string s,ans="";
    cin>>s;
    int n = s.length();

    vector<bool> used(n,false);

    for(int i=0 ; i<n ; ){
        if(used[i]){
            ++i;
            continue;
        }

        int num = s[i]-'0';
        int numi = i;
        used[i] = true;
        ans.pb(s[i]);
        int bunk = 0;

        //
        // cout<<i<<endl;

        for(int j=i+1 ; j < min(i+10,n) ; ++j){
            if(used[j]){
                ++bunk;
                continue;
            }
            //
            // cout<<j<<endl;

            int trnum = s[j]-'0'-(j-i)+bunk;
            if(trnum > num){
                used[numi] = false;
                numi = j;
                num = trnum;
                ans.ppb();
                ans.pb(s[j]-(j-i)+bunk);
                used[numi] = true;
            }
        }

        //
        // cout<<ans<<endl;
        // prnt(used);

        if(numi == i) ++i;
    }

    cout<<ans<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    // FACT();
    // FACTINV();
    // SIEVE();
    
    int t;
    cin>>t;
 
    while(t--){
        solve();
    }
 
    return 0;
}


Submission (verdict: Time limit exceeded on test 8):
#include <cstdio>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define nl cout<<endl
#define vec vector<int>
#define vecs vector<string>
#define ddv vector<vec>
#define ub upper_bound 
#define lb lower_bound
#define prnt(v) for(auto i:v) cout<<i<<" "; nl
#define inp(v); for(auto &i:v) cin>>i;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int N = 2e5;
const int M = 1e9+7;

int factorials[N+1];
int factInv[N+1];
bool isPrime[N+1];

int gcd(int a,int b){ //O(logb)
    if(!b) return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){ //O(logb)
    return (a*b/gcd(a,b)) % M;
}

int binExp(long long a, int b) { //O(logb)
    a %= M;
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * 1LL * a) % M;
        a = (a * 1LL * a) % M;
        b >>= 1;
    }
    return ans;
}

int inv(int n){ //O(logM)
    return binExp(n,M-2);
}

void FACT(){ //O(N)
    factorials[0] = 1;
    for (int i = 1; i <= N; i++) {
        factorials[i] = factorials[i - 1] * 1LL * i % M;
    }
}

void FACTINV(){ //O(N)
    for (int i = 0; i <= N; i++) {
        factInv[i] = inv(factorials[i]);
    }
}

void SIEVE(){ //O(NloglogN)

    //Pre-compute

    fill(isPrime, isPrime+N, true);
    isPrime[0]=isPrime[1]=false;

    for(int i = 2; i <= N; ++i){
        if(isPrime[i]){
            for(int j=2*i ; j<=N ; j+=i)
                isPrime[j]=false;
        }
    }
}

long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N).

    // Pre-Compute before using this func.
    // FACT();
    // FACTINV();

    if (r > n) return 0;
    return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M;
}

void solve(){
    string s,ans="";
    cin>>s;
    int n = s.length();

    vector<bool> used(n,false);

    for(int i=0 ; i<n ; ){
        if(used[i]){
            ++i;
            continue;
        }

        int num = s[i]-'0';
        int numi = i;
        used[i] = true;
        ans.pb(s[i]);
        int bunk = 0;

        //
        // cout<<i<<endl;

        int cnt = 0;

        for(int j=i+1 ; j < n ; ++j){
            if(used[j]){
                ++bunk;
                continue;
            }
            //
            // cout<<j<<endl;

            int trnum = s[j]-'0'-(j-i)+bunk;
            if(trnum > num){
                used[numi] = false;
                numi = j;
                num = trnum;
                ans.ppb();
                ans.pb(s[j]-(j-i)+bunk);
                used[numi] = true;
            }

            ++cnt;

            if(cnt == 10) break;
        }

        //
        // cout<<ans<<endl;
        // prnt(used);

        if(numi == i) ++i;
    }

    cout<<ans<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    // FACT();
    // FACTINV();
    // SIEVE();
    
    int t;
    cin>>t;
 
    while(t--){
        solve();
    }
 
    return 0;
}