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

Previous submission (verdict: Time limit exceeded on test 6):
// I AM NOT HERE TO PARTICIPATE, I AM HERE TO DOMINATE

#define JAI ios::sync_with_stdio(false);

#define SHREE cin.tie(NULL);

#define RAM cout.tie(NULL);

#include <bits/stdc++.h>



#define f(i, n, k) for (int i; i < n; i += k)

#define pb push_back

#define ppb pop_back

#define int long long

#define mp make_pair

using namespace std;

using vpi = vector < pair < int, int >> ;

using pi = pair < int, int > ;

using vi = vector < int > ;

using mapi = map < int, int > ;

using vvi = vector < vector < int >> ;

#define ff first

#define ss second

#define all(x) x.begin(), x.end()

#define sz(x)(int)(x).size()

const int inf = 9e17;

const int mod = 1e9 + 7;

#define DEBUG(x) cerr << #x << ": " << x << '\n'

template < typename T, typename Y >

istream & operator >> (istream & is, pair < T, Y > & p)

{

is >> p.first >> p.second;

return is;

}

template < typename T, typename Y >

ostream & operator << (ostream & os, pair < T, Y > p)

{

os << p.first << ' ' << p.second << ' ';

return os;

}

template < typename T >

istream & operator >> (istream & is, vector < T > & v)

{

for (auto & i: v)

is >> i;

return is;

}

template < typename T >

ostream & operator << (ostream & os, vector < T > v)

{

for (auto & i: v)

os << i << ' ';

return os;

}



int power(int base, int ex, int mod) {

int res = 1;

while (ex > 0) {

if (ex % 2 == 1) {

res = (res * base) % mod;

}

base = (base * base) % mod;

ex /= 2;

}

return res;

}



void sol() {

string str;

cin>>str;

int n = str.length();





for(int j = 0;j<str.length();j++){

for(int i = 1;i<str.length();i++){



if(str[i] - '0' -1 > str[i-1] - '0'){





str[i] = (str[i] - '0' - 1) + '0' ;



swap(str[i],str[i-1]);

}

}

}

cout<<str;

}



signed main() {



JAI SHREE RAM



int t;

cin >> t;





while (t--) {





sol();

cout<<endl;

}







}

Submission (verdict: Wrong answer on test 1):
// I AM NOT HERE TO PARTICIPATE, I AM HERE TO DOMINATE

#define JAI ios::sync_with_stdio(false);

#define SHREE cin.tie(NULL);

#define RAM cout.tie(NULL);

#include <bits/stdc++.h>



#define f(i, n, k) for (int i; i < n; i += k)

#define pb push_back

#define ppb pop_back

#define int long long

#define mp make_pair

using namespace std;

using vpi = vector < pair < int, int >> ;

using pi = pair < int, int > ;

using vi = vector < int > ;

using mapi = map < int, int > ;

using vvi = vector < vector < int >> ;

#define ff first

#define ss second

#define all(x) x.begin(), x.end()

#define sz(x)(int)(x).size()

const int inf = 9e17;

const int mod = 1e9 + 7;

#define DEBUG(x) cerr << #x << ": " << x << '\n'

template < typename T, typename Y >

istream & operator >> (istream & is, pair < T, Y > & p)

{

is >> p.first >> p.second;

return is;

}

template < typename T, typename Y >

ostream & operator << (ostream & os, pair < T, Y > p)

{

os << p.first << ' ' << p.second << ' ';

return os;

}

template < typename T >

istream & operator >> (istream & is, vector < T > & v)

{

for (auto & i: v)

is >> i;

return is;

}

template < typename T >

ostream & operator << (ostream & os, vector < T > v)

{

for (auto & i: v)

os << i << ' ';

return os;

}



int power(int base, int ex, int mod) {

int res = 1;

while (ex > 0) {

if (ex % 2 == 1) {

res = (res * base) % mod;

}

base = (base * base) % mod;

ex /= 2;

}

return res;

}



void sol() {

string str;

cin>>str;



int n = str.length();

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



int x = 0;

int max_x = -1;

int ind = i;



for(int j = i+1;j<i+11;j++){

if(j>=n) break;



x = (str[j] - '0') - (j-i);



if(x > str[i] - '0'){

if(x > max_x){

max_x = x;

ind = j;

}

}

}

str[ind] = (str[ind] - '0') -ind+i +'0';

swap(str[i],str[ind]);

}

cout<<str;

}



signed main() {



JAI SHREE RAM



int t;

cin >> t;





while (t--) {





sol();

cout<<endl;

}







}