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

Previous submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vl vector<ll> 
#define pb push_back
#define loop(n,i) for(ll i = 0; i < n; i++)
#define fa(i,v) for(auto &i:v)
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define print(x) cout << x << "\n";
#define cl(v) v.clear()
#define all(v) v.begin(),v.end()
#define inf (ll)1e18
#define mod (ll)(1e9+7)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

template <typename T> T input(int n = 1){T tmp;cin >> tmp;return tmp;  }
template <typename T> vector<T> inputn(int n){vector<T> tmp;loop(n,i){
        T _;cin >> _;tmp.pb(_);}return tmp;}

// class node{
//     public:
//     ll value;
//     node * next;
//     node(ll n, node * prev){
//         value = n;
//         prev->next = this;
//     }
// };

string op(string s, ll n){
    char tmp1;
    tmp1 = s[n];
    s[n] = s[n-1];
    s[n-1] = (char)(tmp1-1);
    return s;
}

int main() {
	fastio
	int T = input<int>();
	loop(T,_){
        string s = input<string>();
        int p = 0;
        // node str(s[0]-'0',NULL);
        // node prev = str;
        fa(x,s){
            int i = 1;
            ll best = s[p],pn = 0;
            while(i < 10 -(s[p]-'0') and p+i < s.length()){
                if(s[p+i]-i > best) {
                    best = s[p+i]-i;
                    pn = i;
                }
                i++;
            }
            loop(pn,j){
                s = op(s,p+(pn-j));
            }
            p++;
        }
        cout << s << "\n";
	}
	return 0;
}

Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vl vector<ll> 
#define pb push_back
#define loop(n,i) for(ll i = 0; i < n; i++)
#define fa(i,v) for(auto &i:v)
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define print(x) cout << x << "\n";
#define cl(v) v.clear()
#define all(v) v.begin(),v.end()
#define inf (ll)1e18
#define mod (ll)(1e9+7)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

template <typename T> T input(int n = 1){T tmp;cin >> tmp;return tmp;  }
template <typename T> vector<T> inputn(int n){vector<T> tmp;loop(n,i){
        T _;cin >> _;tmp.pb(_);}return tmp;}

string op(string s, ll n){
    char tmp1;
    tmp1 = s[n];
    s[n] = s[n-1];
    s[n-1] = (char)(tmp1-1);
    return s;
}

int main() {
	fastio
	int T = input<int>();
	loop(T,_){
        string s = input<string>();
        int p = 0;
        fa(x,s){
            int i = 1;
            ll best = s[p],pn = 0;
            while(i < 10 and p+i < s.length()){
                if(s[p+i]-i > best) {
                    best = s[p+i]-i;
                    pn = i;
                }
                i++;
            }
            if(T == 1) cout << s.length() << " " << pn << "\n";
            loop(pn,j){
                s = op(s,p+(pn-j));
            }
            p++;
        }
        cout << s << "\n";
	}
	return 0;
}