ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a.size() == 1){

        cout << a[0];

        continue;

    }

    if(a[1]-1 > a[0]){

        swap(a[1],a[0]);

        a[0] -= 1;

    }

    for(ll i = 2;i<b.size();i++){

        ll k = i;



        while(a[k]-1 > a[k-1] && k > 0){



            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

}



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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    if(b.size() == 1){

        cout << b;

        continue;

    }

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a.size() == 1){

        cout << a[0];

        continue;

    }



    for(ll i = 2;i<b.size();i++){

        ll k = i;



        while(a[k]-1 > a[k-1] && k > 0){



            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

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

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    if(b.size() == 1){

        cout << b;

        continue;

    }

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a.size() == 1){

        cout << a[0];

        continue;

    }



    for(ll i = 2;i<b.size();i++){

        ll k = i;



        while(a[k]-1 > a[k-1] && k > 0){



            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

        string b;

        cin >> b;



        vector<int> a;

        for(ll i = 0;i<b.size();i++){

            a.push_back((int)b[i]-48);

        }

        if(a.size() == 1) {

            cout << a[0] << endl;

            continue;

        }

        for(ll i = 1;i<b.size();i++){

            ll k = i;



            while(a[k]-1 > a[k-1] && k > 0){



                swap(a[k],a[k-1]);

                a[k-1] -= 1;

                k--;



            }

        }

        for(ll i = 0;i<a.size();i++){

            cout << a[i];

        }

        cout << endl;

    }

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


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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a[1]-1 > a[0]){

        swap(a[1],a[0]);

        a[0] -= 1;

    }

    for(ll i = 2;i<b.size();i++){

        ll k = i;

        while(a[k]-1 > a[k-1]){

            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

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

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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a[1]-1 > a[0]){

        swap(a[1],a[0]);

        a[0] -= 1;

    }

    for(ll i = 2;i<b.size();i++){

        ll k = i;

        while(a[k]-1 > a[k-1]){

            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

}



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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a.size() == 1){

        cout << a[0];

        continue;

    }

    if(a[1]-1 > a[0]){

        swap(a[1],a[0]);

        a[0] -= 1;

    }

    for(ll i = 2;i<b.size();i++){

        ll k = i;

        while(a[k]-1 > a[k-1]){

            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

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

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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a.size() == 1){

        cout << a[0];

        continue;

    }

    if(a[1]-1 > a[0]){

        swap(a[1],a[0]);

        a[0] -= 1;

    }

    for(ll i = 2;i<b.size();i++){

        ll k = i;

        while(a[k]-1 > a[k-1]){

            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

}



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

using namespace std;



#define ll long long

#define fr first

#define sc second

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



signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll t;

    cin >> t;

    while(t--){

    string b;

    cin >> b;

    vector<int> a;

    for(ll i = 0;i<b.size();i++){

        a.push_back((int)b[i]-48);

    }

    if(a.size() == 1){

        cout << a[0];

        continue;

    }

    if(a[1]-1 > a[0]){

        swap(a[1],a[0]);

        a[0] -= 1;

    }

    for(ll i = 2;i<b.size();i++){

        ll k = i;



        while(a[k]-1 > a[k-1] && k > 0){



            swap(a[k],a[k-1]);

            a[k-1] -= 1;

            k--;



        }

    }

    for(ll i = 0;i<a.size();i++){

        cout << a[i];

    }

    cout << endl;

    }

}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 1e5 + 5;
int a[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	int l,r;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d",&l,&r);
		bitset<35> ll(l),rr(r),a,b,c;
		for (int i=30;i>=0;i--)
		{
			if (rr[i])
			{
				a[i]=1;
				if (ll[i])
					b[i]=c[i]=1;
				else
				{
					for (int j=i-1;j>=0;j--)
						b[j]=c[j]=1;
					break;
				}
			}
		}
		printf("%lld %lld %lld\n",a.to_ullong(),b.to_ullong(),c.to_ullong());
	}
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 1e5 + 5;
int a[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	int l,r;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d",&l,&r);
		bitset<35> ll(l),rr(r),a,b,c;
		for (int i=30;i>=0;i--)
		{
			if (rr[i])
			{
				a[i]=1;
				if (ll[i])
					b[i]=c[i]=1;
				else
				{
					for (int j=i-1;j>=0;j--)
						b[j]=c[j]=1;
					for (int j=i-1;j>=0;j--)
					{
						b[j]=0;
						if (b.to_ullong()>=l&&b.to_ullong()<=r)
							goto l;
						b[j]=1;
					}
					b[i]=1;
					l:;
					break;
				}
			}
		}
		printf("%lld %lld %lld\n",a.to_ullong(),b.to_ullong(),c.to_ullong());
	}
}

Submission (verdict: Accepted):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 1e5 + 5;
int a[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	int l,r;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d",&l,&r);
		bitset<35> ll(l),rr(r),a,b,c;
		for (int i=30;i>=0;i--)
		{
			if (rr[i])
			{
				a[i]=1;
				if (ll[i])
					b[i]=c[i]=1;
				else
				{
					for (int j=i-1;j>=0;j--)
						b[j]=c[j]=1;
					for (int j=i-1;j>=0;j--)
					{
						b[j]=0;
						if (b.to_ullong()>=l&&b.to_ullong()<=r)
							goto l;
						b[j]=1;
					}
					b[i]=1;
					for (int j=i-1;j>0;j--)
						b[j]=0;
					l:;
					break;
				}
			}
		}
		printf("%lld %lld %lld\n",a.to_ullong(),b.to_ullong(),c.to_ullong());
	}
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 1e5 + 5;
int a[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	int l,r;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d",&l,&r);
		bitset<35> ll(l),rr(r),a,b,c;
		for (int i=30;i>=0;i--)
		{
			if (rr[i])
			{
				a[i]=1;
				if (ll[i])
					b[i]=c[i]=1;
				else
				{
					for (int j=i-1;j>=0;j--)
						b[j]=c[j]=1;
					b[0]=0;
					break;
				}
			}
		}
		printf("%lld %lld %lld\n",a.to_ullong(),b.to_ullong(),c.to_ullong());
	}
}

Submission (verdict: Wrong answer on test 2):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 1e5 + 5;
int a[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	int l,r;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d",&l,&r);
		bitset<35> ll(l),rr(r),a,b,c;
		for (int i=30;i>=0;i--)
		{
			if (rr[i])
			{
				a[i]=1;
				if (ll[i])
					b[i]=c[i]=1;
				else
				{
					for (int j=i-1;j>=0;j--)
						b[j]=c[j]=1;
					for (int j=i-1;j>=0;j--)
					{
						b[j]=0;
						if (b.to_ullong()>=l&&b.to_ullong()<=r)
							goto l;
						b[j]=1;
					}
					b[i]=1;
					l:;
					break;
				}
			}
		}
		printf("%lld %lld %lld\n",a.to_ullong(),b.to_ullong(),c.to_ullong());
	}
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 1e5 + 5;
int a[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	int l,r;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d",&l,&r);
		bitset<35> ll(l),rr(r),a,b,c;
		for (int i=30;i>=0;i--)
		{
			if (rr[i])
			{
				a[i]=1;
				if (ll[i])
					b[i]=c[i]=1;
				else
				{
					for (int j=i-1;j>=0;j--)
						b[j]=c[j]=1;
					break;
				}
			}
		}
		printf("%lld %lld %lld\n",a.to_ullong(),b.to_ullong(),c.to_ullong());
	}
}

Submission (verdict: Wrong answer on test 1):
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 1e5 + 5;
int a[maxn];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	int l,r;
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d %d",&l,&r);
		bitset<35> ll(l),rr(r),a,b,c;
		for (int i=30;i>=0;i--)
		{
			if (rr[i])
			{
				a[i]=1;
				if (ll[i])
					b[i]=c[i]=1;
				else
				{
					for (int j=i-1;j>=0;j--)
						b[j]=c[j]=1;
					b[0]=0;
					break;
				}
			}
		}
		printf("%lld %lld %lld\n",a.to_ullong(),b.to_ullong(),c.to_ullong());
	}
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

 

using namespace std;

 

#define int long long

 

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

 

    int t;  cin>>t;

 

    while(t--)

    {

    	int n,l,r;  cin>>n>>l>>r;



    	vector<int> v(n);



    	for(int i=0; i<n; i++) cin>>v[i];



    	sort(v.begin(), v.end());



        int ans=0;



        for(int i=0; i< r-l+1; i++) ans += v[i];



        cout<<ans<<"\n";



 

    }

 

    return 0;

}

 

Submission (verdict: Accepted):
#include<bits/stdc++.h>

 

using namespace std;

 

#define int long long

 

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

 

    int t;  cin>>t;

 

    while(t--)

    {

    	int n,l,r;  cin>>n>>l>>r;



    	vector<int> v(n);



    	for(int i=0; i<n; i++) cin>>v[i];



    	vector<int> left, right;



        for(int i=0; i<r; i++) left.push_back(v[i]);

        for(int i=l-1; i<n; i++) right.push_back(v[i]);



        sort(left.begin(), left.end());

        sort(right.begin(), right.end());



        

        /*for(int i=0; i<left.size(); i++) cout<<left[i]<<" ";

        cout<<"\n";

        for(int i=0; i<right.size(); i++) cout<<right[i]<<" ";

        cout<<"\n";*/



        int c1 = 0;



        for(int i=0; i<r-l+1; i++) c1+= left[i];



        int c2 =  0;

        for(int i=0; i<r-l+1; i++) c2+= right[i];

        

        cout<<min(c1, c2)<<"\n";





 

    }

 

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
 
    int t;  cin>>t;
 
    while(t--)
    {
    	int n,l,r;  cin>>n>>l>>r;

    	vector<int> v(n);

    	for(int i=0; i<n; i++) cin>>v[i];

    	sort(v.begin(), v.end());

        int ans=0;

        for(int i=0; i< (r-l)+1; i++) ans += v[i];

        cout<<ans<<"\n";

 
    }
 
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
 
    int t;  cin>>t;
 
    while(t--)
    {
    	int n,l,r;  cin>>n>>l>>r;

    	vector<int> v(n);

    	for(int i=0; i<n; i++) cin>>v[i];

    	sort(v.begin(), v.end());

        int ans=0;

        for(int i=0; i< (r-l)+1; i++) ans += v[i];

        cout<<ans<<"\n";

 
    }
 
    return 0;
}
 

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

 

using namespace std;

 

#define int long long

 

signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

 

    int t;  cin>>t;

 

    while(t--)

    {

    	int n,l,r;  cin>>n>>l>>r;



    	vector<int> v(n);



    	for(int i=0; i<n; i++) cin>>v[i];



    	sort(v.begin(), v.end());



        int ans=0;



        for(int i=0; i< r-l+1; i++) ans += v[i];



        cout<<ans<<"\n";



 

    }

 

    return 0;

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

Previous submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>

#define int long long
#define pii pair<int, int>
const int MOD = 1e9 + 7;
using namespace std;



string move (string& s, int start, int end) {
    int x=s[end]-'0';
    x-=(end-start);

    // string temp = s.substr(0, start);
    // temp+= '0'+x;
    // temp+=s.substr(start, end);
    // // temp+=s.substr(end+1);

    s.insert(start, 1, '0'+x);
    s.erase(end+1, 1);
    return s;
}

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

    // cout<<move(s,1,3)<<endl;


    for (int i=0;i<s.size();i++) {
        int cmp=-1;
        int ind=-1;
        for (int j=i+1;j<=i+9 && j<s.size();j++) {
            if (s[j]-'0' -j+i > s[i]-'0' && s[j]-'0' -j+i > cmp) {
                cmp = s[j]-'0' -j+i;
                ind = j;
            }
        }
        if (cmp!=-1) {
            s = move(s, i, ind);
            // cout<<"reached: "<<i<<"  "<<ind<<endl;
        
        }

    } 
    cout<<s<<endl;
    
}

signed main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t; cin >> t;
    while(t--) solve();
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long
using namespace std;

string move(string& s, int start, int end) {
    if (start==end) return s;

    int x = s[end] - '0';
    x -= (end - start);

    s.insert(start, 1, '0' + x);
    s.erase(end + 1, 1);
    return s;
}

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

    vector<int> op(s.size(), -1);
    deque<int> dq;

    for (int i = s.size() - 1; i >= 0; --i) {
        
        while (!dq.empty() && dq.front() > i + 9) {
            dq.pop_front();
        }
        
        while (!dq.empty() && s[dq.back()] - '0' - (dq.back() - i) <= s[i] - '0') {
            dq.pop_back(); 
        }

        if (!dq.empty()) {
            op[i] = dq.front();
        }

        dq.push_back(i);
    }

    for (int i = 0; i < s.size(); ++i) {
        if (op[i] != -1) {
            s = move(s, i, op[i]);
        }
    }

    cout << s << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t;
    cin >> t;
    while (t--) solve();
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long
using namespace std;

string move(string& s, int start, int end) {
    if (start==end) return s;

    int x = s[end] - '0';
    x -= (end - start);

    s.insert(start, 1, '0' + x);
    s.erase(end + 1, 1);
    return s;
}

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

    vector<int> op(s.size(), -1);
    deque<int> dq;

    for (int i = s.size() - 1; i >= 0; --i) {
        
        while (!dq.empty() && dq.front() > i + 9) {
            dq.pop_front();
        }
        
        while (!dq.empty() && s[dq.back()] - '0' - (dq.back() - i) <= s[i] - '0') {
            dq.pop_back(); 
        }

        if (!dq.empty()) {
            op[i] = dq.front();
        }

        dq.push_back(i);
    }

    for (int i = 0; i < s.size(); ++i) {
        if (op[i] != -1) {
            s = move(s, i, op[i]);
        }
    }

    cout << s << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t;
    cin >> t;
    while (t--) solve();
}


Submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
const int MOD = 1e9 + 7;
using namespace std;

string move(string& s, int start, int end) {
    int x = s[end] - '0';
    x -= (end - start);
    s.reserve(s.length() + 1);
    char digit = '0' + x;
    s = s.substr(0, start) + digit + s.substr(start, end - start) + s.substr(end + 1);
    return s;
}

void solve() {
    string s;
    cin >> s;
 
    // cout<<move(s,1,3)<<endl;
 
 
    for (int i=0;i<s.size();i++) {
        int cmp=-1;
        int ind=-1;
        for (int j=i+1;j<=i+9 && j<s.size();j++) {
            if (s[j]-'0' -j+i > s[i]-'0' && s[j]-'0' -j+i > cmp) {
                cmp = s[j]-'0' -j+i;
                ind = j;
            }
        }
        if (cmp!=-1) {
            s = move(s, i, ind);
            // cout<<"reached: "<<i<<"  "<<ind<<endl;
        
        }
 
    } 
    cout<<s<<endl;
    
}
 
signed main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t; cin >> t;
    while(t--) solve();
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 7):
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
const int MOD = 1e9 + 7;
using namespace std;

string move(string& s, int start, int end) {
    int x = s[end] - '0';
    x -= (end - start);
    s.reserve(s.length() + 1);
    char digit = '0' + x;
    s = s.substr(0, start) + digit + s.substr(start, end - start) + s.substr(end + 1);
    return s;
}

void solve() {
    string s;
    cin >> s;
 
    // cout<<move(s,1,3)<<endl;
 
 
    for (int i=0;i<s.size();i++) {
        int cmp=-1;
        int ind=-1;
        for (int j=i+1;j<=i+9 && j<s.size();j++) {
            if (s[j]-'0' -j+i > s[i]-'0' && s[j]-'0' -j+i > cmp) {
                cmp = s[j]-'0' -j+i;
                ind = j;
            }
        }
        if (cmp!=-1) {
            s = move(s, i, ind);
            // cout<<"reached: "<<i<<"  "<<ind<<endl;
        
        }
 
    } 
    cout<<s<<endl;
    
}
 
signed main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t; cin >> t;
    while(t--) solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

#define int long long
#define pii pair<int, int>
const int MOD = 1e9 + 7;
using namespace std;



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

    // cout<<move(s,1,3)<<endl;


    for (int i=0;i<s.size();i++) {
        int cmp=-1;
        int ind=-1;
        for (int j=i+1;j<=i+9 && j<s.size();j++) {
            if (s[j]-'0' -j+i > s[i]-'0' && s[j]-'0' -j+i > cmp) {
                cmp = s[j]-'0' -j+i;
                ind = j;
            }
        }
        if (cmp!=-1) {
            while (ind>i) {
                s[ind]--;
                swap(s[ind],s[ind-1]);
                ind--;
            }
        
        }

    } 
    cout<<s<<endl;
    
}

signed main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
#endif
    int t; cin >> t;
    while(t--) solve();
}