ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()

{

    int t;

    cin>>t;

    while(t--)

    {

        int n,l,r;

        cin>>n>>l>>r;

        vector<int>v(n);

        for(auto &i:v)

            cin>>i;

        sort(v.begin(),v.begin()+l-1);

        sort(v.begin()+l-1,v.begin()+r);

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

        // for(auto ele:v)

        //     cout<<ele<<" ";

        // cout<<"\n";

        int sum=accumulate(v.begin()+l-1,v.begin()+r,0);

        int i=0,j=r-1,sum1=sum;

        while(v[i]<=v[j] and i<l-1 and j>=l-1)

        {

            sum1-=v[j];

            sum1+=v[i];

            i++;

            j--;

        }

        i=r-1,j=r;

        while(v[i]>=v[j] and i>=l-1 and j<n)

        {

            sum-=v[i];

            sum+=v[j];

            i--;

            j++;

        }

        cout<<min(sum1,sum)<<"\n";

    }

}





Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>v(n);
        for(auto &i:v)
            cin>>i;
        sort(v.begin(),v.begin()+l-1);
        sort(v.begin()+l-1,v.begin()+r);
        sort(v.begin()+r,v.end());
        // for(auto ele:v)
        //     cout<<ele<<" ";
        // cout<<"\n";
        long long sum=accumulate(v.begin()+l-1,v.begin()+r,0LL);
        long long i=0,j=r-1,sum1=sum;
        while(v[i]<=v[j] and i<l-1 and j>=l-1)
        {
            sum1-=v[j];
            sum1+=v[i];
            i++;
            j--;
        }
        i=r-1,j=r;
        while(v[i]>=v[j] and i>=l-1 and j<n)
        {
            sum-=v[i];
            sum+=v[j];
            i--;
            j++;
        }
        cout<<min(sum1,sum)<<"\n";
    }
}
Problem: 2062C - Cirno and Operations
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
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n-1) {
        reverse(a.begin(),a.end());
        loop (j,0,n-i-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/

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

#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n-1) {
        if (a[n-1] < a[0]) reverse(a.begin(),a.end());
        loop (j,0,n-i-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n-1) {
        if (a[n-1] < a[0]) reverse(a.begin(),a.end());
        loop (j,0,n-i-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/

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

#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n) {
        reverse(a.begin(),a.end());
        loop (j,0,a.size()-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n) {
        if (a[a.size()-1] < a[0]) reverse(a.begin(),a.end());
        loop (j,0,a.size()-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/

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

#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n-1) {
        if (a[a.size()-1] < a[0]) reverse(a.begin(),a.end());
        loop (j,0,a.size()-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

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

#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n) {
        reverse(a.begin(),a.end());
        loop (j,0,a.size()-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/

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

#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n) {
        if (a[a.size()-1] < a[0]) reverse(a.begin(),a.end());
        loop (j,0,a.size()-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/
Problem: 2062C - Cirno and Operations
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
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;

int mod = 1e9+7;

void solve() {
    int n;
    cin>>n;
    vector<int> a(n);
    inputV(a);
    int ans = accumulate(a.begin(),a.end(),0LL);
    loop (i,0,n-1) {
        reverse(a.begin(),a.end());
        loop (j,0,n-i-1) {
            a[j] = a[j+1]-a[j];
        }
        a.pop_back();
        // printV(a);
        ans = max(ans,accumulate(a.begin(),a.end(),0LL));
    }
    cout<<ans<<endl;
}

int32_t main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*
5
2
4 10
2
2 2
3
4 10 5
3
5 3 5
5
12 13 25 17 30
*/
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


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

using LL = long long int;

using namespace std;



#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



#define inf    INT_MAX

#define ninf   INT_MIN

#define mod    10000007 

#define N      100000

#define pb     push_back



  



int a[2*N];

void solve() {

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

  l--, r--;

  

  int init = 0;

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

    cin>>a[i];

    if (i >= l && i <= r)

      init += a[i];

  }



  sort (a, a + l + 1);

  sort (a + l + 1, a + r + 1);

  if (r + 1 < n) sort (a + r + 1, a + n);







  int mn = 0, sub = 0;

  for (int i = 0, j = r; i<l && j  >= l; i++, j--) {

    if (a[i] >= a[j])

      break;

    mn += a[i];

    sub += a[j];

  }



  mn =  init - sub + mn;



  int mnn = 0;

  sub = 0;

  for (int i = r + 1, j = r; i<n && j  >= l; i++, j--) {

    if (a[i] >= a[j])

      break;

    mnn += a[i];

    sub += a[j];

  }



  mnn = init - sub + mnn;



  cout<<min (min (mn, mnn), init)<<'\n';



} 













int main() {

  fast 

  int nt; cin>>nt;

  while (nt--){

    solve();

  }



  return 0;

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

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

using LL = long long int;

using namespace std;



#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



#define inf    INT_MAX

#define ninf   INT_MIN

#define mod    10000007 

#define N      100000

#define pb     push_back



  



int a[2*N];

void solve() {

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

  l--, r--;

  

  int init = 0;

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

    cin>>a[i];

    if (i >= l && i <= r)

      init += a[i];

  }



  sort (a, a + l);

  sort (a + l, a + r + 1);

  if (r + 1 < n) sort (a + r + 1, a + n);







  int mn = 0, sub = 0;

  for (int i = 0, j = r; i<l && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mn += a[i];

    sub += a[j];

  }



  mn =  init - sub + mn;



  int mnn = 0;

  sub = 0;

  for (int i = r + 1, j = r; i<n && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mnn += a[i];

    sub += a[j];

  }



  mnn = init - sub + mnn;



  cout<<min (min (mn, mnn), init)<<'\n';



} 













int main() {

  fast 

  int nt; cin>>nt;

  while (nt--){

    solve();

  }



  return 0;

}



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

using LL = long long int;

using namespace std;



#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



#define inf    INT_MAX

#define ninf   INT_MIN

#define mod    10000007 

#define N      100000

#define pb     push_back



  



int a[2*N];

void solve() {

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

  l--, r--;

  

  LL init = 0;

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

    cin>>a[i];

    if (i >= l && i <= r)

      init += a[i];

  }



  sort (a, a + l);

  sort (a + l, a + r + 1);

  if (r + 1 < n) sort (a + r + 1, a + n);







  LL mn = 0, sub = 0;

  for (int i = 0, j = r; i<l && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mn += a[i];

    sub += a[j];

  }



  mn =  init - sub + mn;



  LL mnn = 0;

  sub = 0;

  for (int i = r + 1, j = r; i<n && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mnn += a[i];

    sub += a[j];

  }



  mnn = init - sub + mnn;



  cout<<min (min (mn, mnn), init)<<'\n';



} 













int main() {

  fast 

  int nt; cin>>nt;

  while (nt--){

    solve();

  }



  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 LL = long long int;

using namespace std;



#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



#define inf    INT_MAX

#define ninf   INT_MIN

#define mod    10000007 

#define N      100000

#define pb     push_back



  



int a[2*N];

void solve() {

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

  l--, r--;

  

  int init = 0;

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

    cin>>a[i];

    if (i >= l && i <= r)

      init += a[i];

  }



  sort (a, a + l + 1);

  sort (a + l + 1, a + r + 1);

  if (r + 1 < n) sort (a + r + 1, a + n);







  int mn = 0, sub = 0;

  for (int i = 0, j = r; i<l && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mn += a[i];

    sub += a[j];

  }



  mn =  init - sub + mn;



  int mnn = 0;

  sub = 0;

  for (int i = r + 1, j = r; i<n && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mnn += a[i];

    sub += a[j];

  }



  mnn = init - sub + mnn;



  cout<<min (min (mn, mnn), init)<<'\n';



} 













int main() {

  fast 

  int nt; cin>>nt;

  while (nt--){

    solve();

  }



  return 0;

}



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

using LL = long long int;

using namespace std;



#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



#define inf    INT_MAX

#define ninf   INT_MIN

#define mod    10000007 

#define N      100000

#define pb     push_back



  



int a[2*N];

void solve() {

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

  l--, r--;

  

  int init = 0;

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

    cin>>a[i];

    if (i >= l && i <= r)

      init += a[i];

  }



  sort (a, a + l);

  sort (a + l, a + r + 1);

  if (r + 1 < n) sort (a + r + 1, a + n);







  int mn = 0, sub = 0;

  for (int i = 0, j = r; i<l && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mn += a[i];

    sub += a[j];

  }



  mn =  init - sub + mn;



  int mnn = 0;

  sub = 0;

  for (int i = r + 1, j = r; i<n && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mnn += a[i];

    sub += a[j];

  }



  mnn = init - sub + mnn;



  cout<<min (min (mn, mnn), init)<<'\n';



} 













int main() {

  fast 

  int nt; cin>>nt;

  while (nt--){

    solve();

  }



  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 LL = long long int;

using namespace std;



#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



#define inf    INT_MAX

#define ninf   INT_MIN

#define mod    10000007 

#define N      100000

#define pb     push_back



  



int a[2*N];

void solve() {

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

  l--, r--;

  

  int init = 0;

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

    cin>>a[i];

    if (i >= l && i <= r)

      init += a[i];

  }



  sort (a, a + l + 1);

  sort (a + l + 1, a + r + 1);

  if (r + 1 < n) sort (a + r + 1, a + n);







  int mn = 0, sub = 0;

  for (int i = 0, j = r; i<l && j  >= l; i++, j--) {

    if (a[i] >= a[j])

      break;

    mn += a[i];

    sub += a[j];

  }



  mn =  init - sub + mn;



  int mnn = 0;

  sub = 0;

  for (int i = r + 1, j = r; i<n && j  >= l; i++, j--) {

    if (a[i] >= a[j])

      break;

    mnn += a[i];

    sub += a[j];

  }



  mnn = init - sub + mnn;



  cout<<min (min (mn, mnn), init)<<'\n';



} 













int main() {

  fast 

  int nt; cin>>nt;

  while (nt--){

    solve();

  }



  return 0;

}



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

using LL = long long int;

using namespace std;



#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



#define inf    INT_MAX

#define ninf   INT_MIN

#define mod    10000007 

#define N      100000

#define pb     push_back



  



int a[2*N];

void solve() {

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

  l--, r--;

  

  int init = 0;

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

    cin>>a[i];

    if (i >= l && i <= r)

      init += a[i];

  }



  sort (a, a + l + 1);

  sort (a + l + 1, a + r + 1);

  if (r + 1 < n) sort (a + r + 1, a + n);







  int mn = 0, sub = 0;

  for (int i = 0, j = r; i<l && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mn += a[i];

    sub += a[j];

  }



  mn =  init - sub + mn;



  int mnn = 0;

  sub = 0;

  for (int i = r + 1, j = r; i<n && j  >= l; i++, j--) {

    if (a[i] > a[j])

      break;

    mnn += a[i];

    sub += a[j];

  }



  mnn = init - sub + mnn;



  cout<<min (min (mn, mnn), init)<<'\n';



} 













int main() {

  fast 

  int nt; cin>>nt;

  while (nt--){

    solve();

  }



  return 0;

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

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;

string solve (string s){
    for(int i=1; i<s.size(); i++){
        if(s[i] - s[i-1] > 1) {
            swap(s[i], s[i-1]);
            s[i-1] -= 1;
            // cout <<s << endl;
            return max(s, solve(s));
        }
    }

    return s;
}



int main()
{
    int t; cin >> t;

    while(t--){
        string s;
        cin >> s;

        cout << solve(s) << endl;
    }

    // cout << solve("5891917899") << endl;
    

    return 0;
}

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

string solve (string s){
    for(int i=0; i<s.size(); i++){
        int diff = s[i]-'0';
        int n = s.length();
        int up_lim = min(i+diff+1, n);
        for(int j=i+1; j<up_lim; j++){
            if(s[j] - s[i]> j - i) {
                swap(s[i], s[j]);
                s[i] -= j-i;
                return solve(s);
            }
        }
        // Move the return statement outside the nested for loop
        
    }
    return s;
}

int main()
{
    int t; cin >> t;

    while(t--){
        string s;
        cin >> s;

        cout << solve(s) << endl;
    }

    // cout << solve("13")<< endl;
    

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


Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;

string solve (string s){
    for(int i=1; i<s.size(); i++){
        if(s[i] - s[i-1] > 1) {
            swap(s[i], s[i-1]);
            s[i-1] -= 1;
            // cout <<s << endl;
            return max(s, solve(s));
        }
    }

    return s;
}



int main()
{
    int t; cin >> t;

    while(t--){
        string s;
        cin >> s;

        cout << solve(s) << endl;
    }

    // cout << solve("5891917899") << endl;
    

    return 0;
}
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;

string solve (string s){
    for(int i=0; i<s.size(); i++){
        int diff = s[i]-'0';
        int n = s.length();
        int up_lim = min(i+diff+1, n);
        for(int j=i+1; j<up_lim; j++){
            if(s[j] - s[i]> j - i) {
                swap(s[i], s[j]);
                s[i] -= j-i;
                return solve(s);
            }
        }
        // Move the return statement outside the nested for loop
        
    }
    return s;
}

int main()
{
    int t; cin >> t;

    while(t--){
        string s;
        cin >> s;

        cout << solve(s) << endl;
    }

    // cout << solve("13")<< endl;
    

    return 0;
}

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

string solve (string s){
    for(int i=0; i<s.size(); i++){
        int cur = s[i]-'0';
        int pos = i;
        for(int j=i; j<min(i+10, (int)s.length()); j++){
            if(s[j]-'0'-(j-i)>cur){
                pos=j;
                cur = s[j]-(j-i)-'0';
            }
        }

        while(pos > i){
            swap(s[pos], s[pos-1]);
            pos--;
        }
        s[i] = cur + '0';
        
    }
    return s;
}

int main()
{
    int t; cin >> t;

    while(t--){
        string s;
        cin >> s;

        cout << solve(s) << endl;
    }

    // cout << solve("13")<< endl;
    

    return 0;
}