ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 11):
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<unordered_map>
using namespace std;
void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector <int>q(n);
        unordered_map<int, int>q1;
        for (int i = 0; i < n; i++) {
            cin >> q[i];
            q1[q[i]]++;
        }
        int a = q1.size();
        vector<pair<int, int>>q2(q1.begin(), q1.end());
        sort(q2.begin(), q2.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
            return a.second < b.second||(a.second==b.second&&a.first<b.first);
            });
        for (const auto& q3 : q2) {
            if (q3.second <= k) {
                k -= q3.second;
                a--;
            }
            else {
                break;
            }
        }
        if (a == 0) {
            cout << "1" << endl; continue;
        }
        cout << a << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 11):
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<unordered_map>
using namespace std;
void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector <int>q(n);
        unordered_map<int, int>q1;
        for (int i = 0; i < n; i++) {
            cin >> q[i];
            q1[q[i]]++;
        }
        vector<int>q2;
        for (const auto x : q1) {
            q2.push_back(x.second);
        }
        int a = q2.size();
        sort(q2.begin(), q2.end());
        for (int i = 0; i < q2.size(); i++) {
            if (q2[i] <= k) {
                k -= q2[i];
                a--;
            }
        }
        cout << max(1, a) << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
const int mod = 1e9+10;
int n,m,q,k;
void solve(){
    cin>>n>>k;
    vector<int>v(n);
    map<int,int>mp;
    for (int i =0;i<n;i++) {
        cin>>v[i];
        mp[v[i]]++;
    }
    int cnt =0;
    vector<pair<int,int>>pa;
    for (auto i:mp) {
        pa.push_back({i.second,i.first});
    }
    sort(all(pa));
    for (int i =0;i<pa.size()-1;i++) {
        if (pa[i].first<=k) {
            cnt++;
            k-=pa[i].first;
        }
    }
    cout<<mp.size()-cnt<<endl;
}
signed main(){
    int t  =1;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 11):
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<unordered_map>
using namespace std;
void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector <int>q(n);
        unordered_map<int, int>q1;
        for (int i = 0; i < n; i++) {
            cin >> q[i];
            q1[q[i]]++;
        }
        int a = q1.size();
        vector<pair<int, int>>q2(q1.begin(), q1.end());
        sort(q2.begin(), q2.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
            return a.second < b.second||(a.second==b.second&&a.first<b.first);
            });
        for (const auto& q3 : q2) {
            if (q3.second <= k) {
                k -= q3.second;
                a--;
            }
            else {
                break;
            }
        }
        if (a == 0) {
            cout << "1" << endl; continue;
        }
        cout << a << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

Submission (verdict: Compilation error):
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<unordered_map>
using namespace std;
void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector <int>q(n);
        unordered_map<int, int>q1;
        for (int i = 0; i < n; i++) {
            cin >> q[i];
            q1[q[i]]++;
        }
        vector<int>q2;
        for (const auto x : q1) {
            q2.push_back(x.second);
        }
        int a = q2.size();
        sort(q2.begin(), q2.end());
        for (int i = 0; i < q2.size(), i++) {
            if (q2[i] <= k) {
                k -= q2[i];
                a--;
            }
        }
        cout << max(1, a) << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


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

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,k;
        map<int,int>m;
        cin>>n>>k;
        int arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
            m[arr[i]]++;
        }
        vector<int>v;
        for (auto x:m){
            v.push_back(x.second);
        }
        sort(v.begin(),v.end());
        int a=v.size();
        int i=0;
        while (k>0 && a>1){
            k-=v[i];
            a--;
        }
        cout<<a<<'\n';
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,k;
        map<int,int>m;
        cin>>n>>k;
        int arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
            m[arr[i]]++;
        }
        vector<int>v;
        for (auto x:m){
            v.push_back(x.second);
        }
        sort(v.begin(),v.end());
        int a=v.size();
        int i=0;
        while (k>0 && a>1){
            k-=v[i];
            a--;
            i++;
        }
        cout<<a<<'\n';
    }
    return 0;
}

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

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,k;
        map<int,int>m;
        cin>>n>>k;
        int arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
            m[arr[i]]++;
        }
        vector<int>v;
        for (auto x:m){
            v.push_back(x.second);
        }
        sort(v.begin(),v.end());
        int a=v.size();
        int i=0;
        while (k>0 && a>1){
            k-=v[i];
            if (k>=0){
            a--;
            i++;
            }
        }
        cout<<a<<'\n';
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,k;
        map<int,int>m;
        cin>>n>>k;
        int arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
            m[arr[i]]++;
        }
        vector<int>v;
        for (auto x:m){
            v.push_back(x.second);
        }
        sort(v.begin(),v.end());
        int a=v.size();
        int i=0;
        while (k>0 && a>1){
            k-=v[i];
            a--;
        }
        cout<<a<<'\n';
    }
    return 0;
}

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

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,k;
        map<int,int>m;
        cin>>n>>k;
        int arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
            m[arr[i]]++;
        }
        vector<int>v;
        for (auto x:m){
            v.push_back(x.second);
        }
        sort(v.begin(),v.end());
        int a=v.size();
        int i=0;
        while (k>0 && a>1){
            k-=v[i];
            a--;
            i++;
        }
        cout<<a<<'\n';
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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



using namespace std;



int main()

{

    int t;

    cin>>t;

    while (t--){

        int n,l,r;

        cin>>n>>l>>r;

        int c=r-l+1;

        int arr[n];

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

            cin>>arr[i];

        }

        sort(arr,arr+n);

        int s=0;

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

            s=s+arr[i];

        }

        cout<<s<<'\n';

    }

    return 0;

}

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

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,l,r;
        cin>>n>>l>>r;
        int c=r-l+1;
        long long arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long s=0;
        for (int i=0;i<c;i++){
            s=s+arr[i];
        }
        cout<<s<<'\n';
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--){
        int n,l,r;
        cin>>n>>l>>r;
        int c=r-l+1;
        long long arr[n];
        for (int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long s=0;
        for (int i=0;i<c;i++){
            s=s+arr[i];
        }
        cout<<s<<'\n';
    }
    return 0;
}


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;

        int c=r-l+1;

        long long a[r];

        long long b[n-l+1];

        long long arr[n];

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

            cin>>arr[i];

        }

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

            a[i]=arr[i];

        }

        for (int i=l-1;i<n;i++){

            b[i-l+1]=arr[i];

        }





        sort(a,a+r);

        sort(b,b+n-l+1);

        long long s1=0;

        long long s2=0;

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

            s1=s1+a[i];

            s2=s2+b[i];

        }

        cout<<min(s1,s2)<<'\n';

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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



using namespace std;



int main()

{

    int t;

    cin>>t;

    while (t--){

        int n,l,r;

        cin>>n>>l>>r;

        int c=r-l+1;

        int arr[n];

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

            cin>>arr[i];

        }

        sort(arr,arr+n);

        int s=0;

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

            s=s+arr[i];

        }

        cout<<s<<'\n';

    }

    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve()
{
    int n,k;
    cin>>n>>k;
    map<int,int>mp;
    vector<int>a;
    for(int i=1;i<=n;++i){
        int tmp;
        cin>>tmp;
        mp[tmp]++;
    }
    for(auto [i,j]:mp){
        a.push_back(j);
    }
    sort(a+0,a+n);
    int ans=a.size();
    for (int i=0;i<a.size();++i){
        if (k>=a[i]&&a[i]!= 0){
            k-=a[i];
            ans--;
        }
    }
    cout<<(ans==0?1:ans)<<endl;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve()
{
	int n,m,k;
	cin>>n>>k;
	vector<int>a(n);
	map<int,int>mp;
	for(int i=1;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	deque<int> v;
	for (auto [a, b]:mp){
		v.push_back(b);
	}
	sort(v.begin(), v.end());
	while (k>0 && v.size()>1){
		int t = v.front();
		v.pop_front();
		int yu = t-min(k, t);
		if (yu > 0) v.push_back(yu);
		k-=min(k, t);
	}
	cout << v.size() << endl;
}
 
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve()
{
	int n,m,k;
	cin>>n>>k;
	vector<int>a(n);
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	deque<int>v;
	for (auto[a,b]:mp){
		v.push_back(b);
	}
	sort(v+0,v+n);
	while (k>0&&v.size()>1){
		int t=v.front();
		v.pop_front();
		int ans=t-min(k,t);
		if (ans>0)v.push_back(ans);
		k-=min(k,t);
	}
	cout << v.size()<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve()
{
	int n,m,k;
	cin>>n>>k;
	vector<int>a(n);
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	deque<int>v;
	for (auto[a,b]:mp){
		v.push_back(b);
	}
	sort(v.begin(),v.end());
	while (k>0&&v.size()>1){
		int t=v.front();
		v.pop_front();
		int ans=t-min(k,t);
		if (ans>0)v.push_back(ans);
		k-=min(k,t);
	}
	cout << v.size()<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve()
{
    int n,k;
    cin>>n>>k;
    map<int,int>mp;
    vector<int>a;
    for(int i=1;i<=n;++i){
        int tmp;
        cin>>tmp;
        mp[tmp]++;
    }
    for(auto [i,j]:mp){
        a.push_back(j);
    }
    sort(a+0,a+n);
    int ans=a.size();
    for (int i=0;i<a.size();++i){
        if (k>=a[i]&&a[i]!= 0){
            k-=a[i];
            ans--;
        }
    }
    cout<<(ans==0?1:ans)<<endl;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve()
{
	int n,m,k;
	cin>>n>>k;
	vector<int>a(n);
	map<int,int>mp;
	for(int i=1;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	deque<int> v;
	for (auto [a, b]:mp){
		v.push_back(b);
	}
	sort(v.begin(), v.end());
	while (k>0 && v.size()>1){
		int t = v.front();
		v.pop_front();
		int yu = t-min(k, t);
		if (yu > 0) v.push_back(yu);
		k-=min(k, t);
	}
	cout << v.size() << endl;
}
 
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}


Submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve()
{
	int n,m,k;
	cin>>n>>k;
	vector<int>a(n);
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	deque<int>v;
	for (auto[a,b]:mp){
		v.push_back(b);
	}
	sort(v+0,v+n);
	while (k>0&&v.size()>1){
		int t=v.front();
		v.pop_front();
		int ans=t-min(k,t);
		if (ans>0)v.push_back(ans);
		k-=min(k,t);
	}
	cout << v.size()<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

int solve(){
    int n, ans=0;
    cin >> n;
    vector<int> adj[n+1], deg(n+1);
    multiset<int> degrees;
    
    for (int i=1; i<=n-1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }

    for (int i=1; i<=n; i++){
        degrees.insert(deg[i]);
    }

    for (int i=1; i<n; i++){
        auto copy = degrees;
        int cnt = deg[i];
        copy.erase(copy.find(deg[i]));
        for (auto j : adj[i]){
            copy.erase(copy.find(deg[j]));
            copy.insert(deg[j]-1);
        }
        cnt += *prev(copy.end());
        ans = max(ans, cnt-1);
    }
    
    return ans;
};

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;

    while (t--){
        cout << solve() << '\n';
    }
    
    return 0;
}

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

int solve(){
    int n, ans=0;
    cin >> n;
    vector<int> adj[n+1], deg(n+1);
    multiset<int> degrees;
    
    for (int i=1; i<=n-1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }

    if (n==2){
        return 0;
    }

    for (int i=1; i<=n; i++){
        degrees.insert(deg[i]);
    }

    for (int i=1; i<n; i++){
        if (deg[i] == *prev(degrees.end())){
            auto copy = degrees;
            int cnt = deg[i];
            copy.erase(copy.find(deg[i]));
            for (auto j : adj[i]){
                copy.erase(copy.find(deg[j]));
                copy.insert(deg[j]-1);
            }
            cnt += *prev(copy.end());
            ans = max(ans, cnt-1);
        }
    }
    
    return ans;
};

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;

    while (t--){
        cout << solve() << '\n';
    }
    
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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

int solve(){
    int n, ans=0;
    cin >> n;
    vector<int> adj[n+1], deg(n+1);
    multiset<int> degrees;
    
    for (int i=1; i<=n-1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }

    for (int i=1; i<=n; i++){
        degrees.insert(deg[i]);
    }

    for (int i=1; i<n; i++){
        auto copy = degrees;
        int cnt = deg[i];
        copy.erase(copy.find(deg[i]));
        for (auto j : adj[i]){
            copy.erase(copy.find(deg[j]));
            copy.insert(deg[j]-1);
        }
        cnt += *prev(copy.end());
        ans = max(ans, cnt-1);
    }
    
    return ans;
};

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;

    while (t--){
        cout << solve() << '\n';
    }
    
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

int solve(){
    int n, ans=0;
    cin >> n;
    vector<int> adj[n+1], deg(n+1);
    multiset<int> degrees;
    
    for (int i=1; i<=n-1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }

    if (n==2){
        return 0;
    }

    for (int i=1; i<=n; i++){
        degrees.insert(deg[i]);
    }

    for (int i=1; i<n; i++){
        if (deg[i] == *prev(degrees.end())){
            auto copy = degrees;
            int cnt = deg[i];
            copy.erase(copy.find(deg[i]));
            for (auto j : adj[i]){
                copy.erase(copy.find(deg[j]));
                copy.insert(deg[j]-1);
            }
            cnt += *prev(copy.end());
            ans = max(ans, cnt-1);
        }
    }
    
    return ans;
};

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;

    while (t--){
        cout << solve() << '\n';
    }
    
    return 0;
}

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

int solve(){
    int n, ans=0;
    cin >> n;
    vector<int> adj[n+1], deg(n+1);
    multiset<int> degrees;
    
    for (int i=1; i<=n-1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }

    if (n==2){
        return 0;
    }

    for (int i=1; i<=n; i++){
        degrees.insert(deg[i]);
    }

    for (int i=1; i<n; i++){
        int cnt = deg[i];
        degrees.erase(degrees.find(deg[i]));
        for (auto j : adj[i]){
            degrees.erase(degrees.find(deg[j]));
            degrees.insert(deg[j]-1);
        }
        cnt += *prev(degrees.end());
        ans = max(ans, cnt-1);
        degrees.insert(deg[i]);
        for (auto j : adj[i]){
            degrees.erase(degrees.find(deg[j]-1));
            degrees.insert(deg[j]);
        }
    }
    
    return ans;
};

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;

    while (t--){
        cout << solve() << '\n';
    }
    
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.size();
        for (int i = 1; i < n; i++) {
            for (int j = i; j > 0; j--) {
                if (s[j] > s[j - 1] + 1) {
                    --s[j];
                    swap(s[j], s[j - 1]);
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.size();
        for (int i = 1; i < n; i++) {
            for (int j = i; j > 0 && s[j] > '0'; j--) {
                if (s[j] > s[j - 1] + 1) {
                    --s[j];
                    swap(s[j], s[j - 1]);
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}

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

using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.size();
        for (int i = 1; i < n; i++) {
            for (int j = i; j > 0 && s[j] > '0' && s[j] > s[j - 1] + 1; j--) {
                --s[j];
                swap(s[j], s[j - 1]);
            }
        }
        cout << s << '\n';
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.size();
        for (int i = 1; i < n; i++) {
            for (int j = i; j > 0; j--) {
                if (s[j] > s[j - 1] + 1) {
                    --s[j];
                    swap(s[j], s[j - 1]);
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 8):
#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.size();
        for (int i = 1; i < n; i++) {
            for (int j = i; j > 0 && s[j] > '0'; j--) {
                if (s[j] > s[j - 1] + 1) {
                    --s[j];
                    swap(s[j], s[j - 1]);
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}