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

Previous submission (verdict: Wrong answer on test 2):
/*_______________________*****________________________*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
/*_______________________MACRO DEFINITIONS ________________________*/
#define endl "\n"
#define int long long  
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int, int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
 
//some useful functions and identifiers as macro
#define ff first
#define ss second
#define pb push_back
#define set_bits __builtin_popcountll
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define pinf 1e18
#define ninf -1e18
#define MOD 1000000007
#define PI 3.141592653589793238462
#define loop(s, e) for(int i = s; i < e; i++)
#define rloop(e, s) for(int i = e; i>= s; i--)
int delrow[4] = {-1,0,1,0};
int delcol[4] = {0,1,0,-1};
 
/*______________________ COMMON FUNCTION DEFINITIONS _________________________*/
 
int gcd(int x , int y){return y == 0 ? x : gcd(y,x%y) ;}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
//XXX Don't use ceil XXX
int ceil2(int a, int b) {
    return (a + b - 1) / b;
}

int mpow(int base, int exp) { //binary exponentiation (modular power) (change MOD if required)
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % MOD;
    base = ((ll)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}
 
int mdivide (int a, int b) {  //valid when MOD is prime
  return ((ll) (a%MOD) * mpow(b,MOD-2)) % MOD;
}

/*_________________________________ DEBUGGER ________________________________*/
#define printvec(arr) for(int i = 0; i < arr.size(); i++){cout<<arr[i]<<" ";}cout<<endl;
#define dbg(x) cout<<"value of "<<#x<<" "<<x<<endl;
 
       
#define MULTI_TESTS

void func( int i, int j,string &s) {

    for (int k = j; k > i; --k) {
        s[k] = s[k - 1];
    }
}

void solve(int testIdx){

 string s;
    cin>>s;
    int n = s.length();
    for(int i=0; i<s.size(); i++){
      int x = s[i]-'0';
      int id = i;
      if(x == 0) continue;
      for(int j=i+1; j<min((ll)s.size(), ll(i+10)); j++){
          int y = s[j]-'0';
          if(y-(j-i) > x){
              id = j;
              x = y-(j-i);
          }
      }
        func(i,id,s);
        s[i] = (char)(x + '0');
  }
  cout<<s<<endl;
  
  
}

int32_t main() {
 
#ifndef ONLINE_JUDGE
  freopen("inputf.in", "r", stdin);
  freopen("outputf.txt", "w", stdout);
#endif
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
  int numTests = 1;
  #ifdef MULTI_TESTS
    cin >> numTests;
  #endif
  for (int testIdx = 1; testIdx <= numTests; testIdx++) {
    solve(testIdx);
  }
  
  return 0;
}

Submission (verdict: Accepted):
/*_______________________*****________________________*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
/*_______________________MACRO DEFINITIONS ________________________*/
#define endl "\n"
#define int long long  
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int, int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
 
//some useful functions and identifiers as macro
#define ff first
#define ss second
#define pb push_back
#define set_bits __builtin_popcountll
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define pinf 1e18
#define ninf -1e18
#define MOD 1000000007
#define PI 3.141592653589793238462
#define loop(s, e) for(int i = s; i < e; i++)
#define rloop(e, s) for(int i = e; i>= s; i--)
int delrow[4] = {-1,0,1,0};
int delcol[4] = {0,1,0,-1};
 
/*______________________ COMMON FUNCTION DEFINITIONS _________________________*/
 
int gcd(int x , int y){return y == 0 ? x : gcd(y,x%y) ;}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
//XXX Don't use ceil XXX
int ceil2(int a, int b) {
    return (a + b - 1) / b;
}

int mpow(int base, int exp) { //binary exponentiation (modular power) (change MOD if required)
  base %= MOD;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % MOD;
    base = ((ll)base * base) % MOD;
    exp >>= 1;
  }
  return result;
}
 
int mdivide (int a, int b) {  //valid when MOD is prime
  return ((ll) (a%MOD) * mpow(b,MOD-2)) % MOD;
}

/*_________________________________ DEBUGGER ________________________________*/
#define printvec(arr) for(int i = 0; i < arr.size(); i++){cout<<arr[i]<<" ";}cout<<endl;
#define dbg(x) cout<<"value of "<<#x<<" "<<x<<endl;
 
       
#define MULTI_TESTS

void func( int i, int j,string &s) {

    for (int k = j; k > i; --k) {
        s[k] = s[k - 1];
    }
}

void solve(int testIdx){

 string s;
    cin>>s;
    int n = s.length();
    for(int i=0; i<s.size(); i++){
      int x = s[i]-'0';
      int id = i;
    //   if(x == 0) continue;
      for(int j=i+1; j<min((ll)s.size(), ll(i+10)); j++){
          int y = s[j]-'0';
          if(y-(j-i) > x){
              id = j;
              x = y-(j-i);
          }
      }
        func(i,id,s);
        s[i] = (char)(x + '0');
  }
  cout<<s<<endl;
  
  
}

int32_t main() {
 
#ifndef ONLINE_JUDGE
  freopen("inputf.in", "r", stdin);
  freopen("outputf.txt", "w", stdout);
#endif
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
  int numTests = 1;
  #ifdef MULTI_TESTS
    cin >> numTests;
  #endif
  for (int testIdx = 1; testIdx <= numTests; testIdx++) {
    solve(testIdx);
  }
  
  return 0;
}