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

Solution 1 (runtime: 61 ms):
#include "bits/stdc++.h"
#include <iostream>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())


void solve() {
    string st;
    cin >> st; 
		for(int i=0;i<st.size()-1;i++){
			if(st[i]<st[i+1]-1){
				swap(st[i],st[i+1]);
				st[i]--;
			if(i>=1) i-=2;
			}
		}
		cout<<st<<'\n';
	}

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

    int t;
    cin >> t;  // Number of test cases
    while (t--) {
        solve();
    }

    return 0;
}


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

/*
// PRIORITY BASED DATA STRUCTURE

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // fi_by_order, order_of_key
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds_pair;
*/

#ifdef ONLINE_JUDGE
#define test(...)
#define deb(...)
#else
#include "deb.h"
#endif

typedef long long int ll;
typedef long double lld;

template <typename T>
void print(const T &x)
{
    cout << x << endl;
}

template <typename T>
void print(const vector<T> &v)
{
    for (const auto &val : v)
        cout << val << " ";
    cout << endl;
}

// coprime / relatively prime
// O(log(min(a, b)))
// ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }

ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; }

// # PAIR
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>

// # VECTOR
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define vstr vector<string>
#define matrix vector<vector<ll>>

// # MAP
#define mpll map<ll, ll>
#define mpcl map<char, ll>

// # SET
#define sll set<ll>
#define msll multiset<ll>
#define sstr set<string>

// # HEAP
#define minHeap priority_queue<ll, vector<ll>, greater<ll>>
#define maxHeap priority_queue<ll>

// # OPS
#define minof(v) (*(min_element(v.begin(), v.end())))
#define maxof(v) (*(max_element(v.begin(), v.end())))
#define sumof(v) (accumulate(v.begin(), v.end(), 0ll))
#define bend(v) v.begin(), v.end()
#define rebend(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define lem size()

// # OTH
#define LINE(str) getline(cin, str, '\n')
#define CEIL(x, y) ceil((double)x / (double)y)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

ll delRow[] = {0, -1, 0, +1};
ll delCol[] = {-1, 0, +1, 0};
// ll delRow[] = {0, -1, -1, -1, 0, +1, +1, +1};
// ll delCol[] = {-1, -1, 0, +1, +1, +1, 0, -1};

const long long int MOD = 1e9 + 7;

ll mod(ll x)
{
    return ((x % MOD) + MOD) % MOD;
}

const long long int N = 1e6 + 5;

struct Node
{
    ll data;
    Node *next;

    Node(ll value) : data(value), next(nullptr) {}
};

Node *create(string &str)
{
    if (str.empty())
        return nullptr;

    Node *head = new Node(str[0] - '0');
    Node *curr = head;

    for (ll i = 1; i < str.length(); i++)
    {
        curr->next = new Node(str[i] - '0');
        curr = curr->next;
    }

    return head;
}

void deleteLL(Node *head)
{
    while (head != nullptr)
    {
        Node *temp = head;
        head = head->next;
        delete temp;
    }
}

void deleteNode(Node *&head, Node *target)
{
    if (head == nullptr || target == nullptr)
        return;

    if (head == target)
    {
        head = head->next;
        delete target;
        return;
    }

    Node *curr = head;
    while (curr->next != nullptr && curr->next != target)
    {
        curr = curr->next;
    }

    if (curr->next == target)
    {
        curr->next = target->next;
        delete target;
    }
}

void solve()
{
    string s, res;
    cin >> s;

    Node *head = create(s), *curr = head;

    ll i = 0;
    while (curr)
    {
        Node *temp = curr->next, *target = nullptr;
        ll cnt = i + 1, maxi = 0;

        while (temp && cnt <= i + 9)
        {
            ll x = temp->data - (cnt - i);

            if (x > maxi)
                maxi = x, target = temp;
            temp = temp->next;
            cnt++;
        }

        if (maxi > curr->data)
        {
            res += (char)(maxi + '0');
            // deb('a');
        }
        else
        {
            res += (char)(curr->data + '0');
            target = curr;
            curr = curr->next;
            // deb('b');
        }
        // deb(i, maxi, (target) ? target->data : -1);
        deleteNode(head, target);

        i++;
    }

    deleteLL(head);

    print(res);
}

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

    ll t = 1, testcase = 1;
    cin >> t;
    while (t--)
    {
        test(testcase++);
        [&]()
        {
            solve();
        }();
    }
    return 0;
}