Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define in(a) lli a; cin>>a

#define out(a) cout<<a<<endl

#define f(i,a,n) for(lli i=a;i<n;i++)

#define lli long long int

#define pb push_back

#define vll vector<lli>v

#define vll(n) vector<lli>v(n)

#define s(x) string x;cin>>x

#define ub(x,l)  upper_bound(x.begin(),x.end(),l)

#define lb(x,l)  lower_bound(x.begin(),x.end(),l)

#define F(i,a,n) for(ll i=n-1;i>=a;i--)

#define ff(x,y)  for(auto x:y)

#define cy  cout<<"YES"<<endl

#define cn  cout<<"NO"<<endl

#define vii(v,n,a) vector<ll> v(n); f(i,a,n){ cin>>v[i]; }

#define xff x.first

#define xss x.second

#define si(x) set<ll>x





const int MOD=1e9+7;

 

 

vector<lli> SieveOfEratosthenes(lli n)

{

    // Create a boolean array "prime[0..n]" and initialize

    // all entries it as true. A value in prime[i] will

    // finally be false if i is Not a prime, else true.

    vector<bool>prime(n+1,true);

    prime[0] = prime[1] = false;

    //bool prime[n + 1];

    //out("hy");

    //memset(prime, true, sizeof(prime));

    //out("hy");

    for (int p = 2; p * p <= n; p++) {

        // If prime[p] is not changed, then it is a prime

        if (prime[p] == true) {

            // Update all multiples of p greater than or

            // equal to the square of it numbers which are

            // multiple of p and are less than p^2 are

            // already been marked.

            for (int i = p * p; i <= n; i += p)

                prime[i] = false;

        }

    }

 

 

    // Print all prime numbers

    vector<lli>ans;

    for (int p = 2; p <= n; p++)

     {   if (prime[p])

            ans.pb(p);

     }

     return ans;

} 

 



 

bool isPrime(lli n)

{

    // Check if n=1 or n=0

    if (n <= 1)

        return false;

    // Check if n=2 or n=3

    if (n == 2 || n == 3)

        return true;

    // Check whether n is divisible by 2 or 3

    if (n % 2 == 0 || n % 3 == 0)

        return false;

    

    // Check from 5 to square root of n

    // Iterate i by (i+6)

    for (int i = 5; i <= sqrt(n); i = i + 6)

        if (n % i == 0 || n % (i + 2) == 0)

            return false;

 

    return true;

}

 

 

bool isPerfectSquare(lli n)

{

    // Base case: 0 and 1 are perfect squares

    if (n <= 1) {

        return true;

    }

 

    // Initialize boundaries for binary search

    long long left = 1, right = n;

 

    while (left <= right) {

 

        // Calculate middle value

        long long mid = left + (right - left) / 2;

 

        // Calculate square of the middle value

        long long square = mid * mid;

 

        // If the square matches n, n is a perfect square

        if (square == n) {

 

            return true;

        }

 

        // If the square is smaller than n, search the right

        // half

        else if (square < n) {

 

            left = mid + 1;

        }

 

        // If the square is larger than n, search the left

        // half

        else {

 

            right = mid - 1;

        }

    }

 

    // If the loop completes without finding a perfect

    // square, n is not a perfect square

    return false;

}

 

 

lli log_a_to_base_b(lli a,lli b)

{

    return log2(a) / log2(b);

}

 

 lli binpow(lli a, lli b) {

	lli res = 1;

	while (b > 0) {

		if (b & 1)

			res = res * a;

		a = a * a;

		b >>= 1;

	}

	return res;

}

 





void solve()

{

    string s="";

    cin>>s;

    lli n=s.size();

    vll(n);

    for(int i=0;i<n;i++)

    {

        int maxi=0;

        lli ind=n;

        for(int j=i;j<i+9;j++)

        {

            if(j>=n)break;

            if(s[j]-'0'-(j-i)>maxi)

            {

                maxi=s[j]-'0'-(j-i);

                ind=j;

            }

        }

        while(ind>i)

        {

            swap(s[ind],s[ind-1]);

            ind--;

        }

        s[i]=char(maxi+'0');

    }

    out(s);  

}



int main()

{

    int t;

    cin>>t;

    while(t--)

    {

        solve();

    }

}