ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];

int C(int x, int y){
    for(int i:G[x])if(y==i)return 1;
    return 0;
}

void solve(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++)G[i].clear();
    for(int i=1; i<n; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int si[LM], Ms=0;
    vector<int>v[LM];
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        printf("%d\n",Ms*2-1);
    if(MsSi==2){
        printf("%d\n",Ms*2-C(v[Ms][0],v[Ms][1])-1);
    }
    else{
        int ws=Ms-1;
        while(v[ws].size()==0)ws--;
        for(int i:v[ws]){
            if(C(i,v[Ms][0])==0){
                printf("%d\n",Ms+ws-1);
                return;
            }
        }
        printf("%d\n",Ms+ws-2);
    }
}

int main(){
    int tc;
    scanf("%d", &tc);
    for(;tc>0;tc--)solve();
}


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];
set<int> S[LM];
vector<int>v[LM];

int C(int x, int y){
    return S[x].find(y)!=S[x].end();
}

void solve(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++)G[i].clear(),v[i].clear();
    for(int i=1; i<n; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
        S[x].insert(y);
        S[y].insert(x);
    }
    int si[LM], Ms=0;
    
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        printf("%d\n",Ms*2-1);
    if(MsSi==2){
        printf("%d\n",Ms*2-C(v[Ms][0],v[Ms][1])-1);
    }
    else{
        int ws=Ms-1;
        while(v[ws].empty())ws--;
        for(int i:v[ws]){
            if(C(i,v[Ms][0])==0){
                printf("%d\n",Ms+ws-1);
                return;
            }
        }
        printf("%d\n",Ms+ws-2);
    }
}

int main(){
    int tc;
    scanf("%d", &tc);
    for(;tc>0;tc--)solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];

int C(int x, int y){
    for(int i:G[x])if(y==i)return 1;
    return 0;
}

void solve(){
    cin>>n;
    for(int i=1; i<=n; i++)G[i].clear();
    for(int i=1; i<n; i++){
        int u,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int si[LM], Ms=0;
    vector<int>v[LM];
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        cout<<Ms*2-1<<'\n';
    if(MsSi==2){
        cout<<Ms*2-C(v[Ms][0],v[Ms][1])-1<<'\n';
    }
    else{
        int ws=Ms-1;
        while(v[ws].size()==0)ws--;
        for(int i:v[ws]){
            if(C(v[Ms][0],i)==0){
                cout<<Ms+ws-1<<'\n';
                return;
            }
        }
        cout<<Ms+ws-2<<'\n';
    }
}

int main(){
    int tc;
    cin>>tc;
    for(;tc>0;tc--)solve();
}


Submission (verdict: Time limit exceeded on test 2):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];

int C(int x, int y){
    for(int i:G[x])if(y==i)return 1;
    return 0;
}

void solve(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++)G[i].clear();
    for(int i=1; i<n; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int si[LM], Ms=0;
    vector<int>v[LM];
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        printf("%d\n",Ms*2-1);
    if(MsSi==2){
        printf("%d\n",Ms*2-C(v[Ms][0],v[Ms][1])-1);
    }
    else{
        int ws=Ms-1;
        while(v[ws].size()==0)ws--;
        for(int i:v[ws]){
            if(C(i,v[Ms][0])==0){
                printf("%d\n",Ms+ws-1);
                return;
            }
        }
        printf("%d\n",Ms+ws-2);
    }
}

int main(){
    int tc;
    scanf("%d", &tc);
    for(;tc>0;tc--)solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];
set<int> S[LM];
vector<int>v[LM];

int C(int x, int y){
    return S[x].find(y)!=S[x].end();
}

void solve(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++)G[i].clear(),v[i].clear();
    for(int i=1; i<n; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
        S[x].insert(y);
        S[y].insert(x);
    }
    int si[LM], Ms=0;
    
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        printf("%d\n",Ms*2-1);
    if(MsSi==2){
        printf("%d\n",Ms*2-C(v[Ms][0],v[Ms][1])-1);
    }
    else{
        int ws=Ms-1;
        while(v[ws].empty())ws--;
        for(int i:v[ws]){
            if(C(i,v[Ms][0])==0){
                printf("%d\n",Ms+ws-1);
                return;
            }
        }
        printf("%d\n",Ms+ws-2);
    }
}

int main(){
    int tc;
    scanf("%d", &tc);
    for(;tc>0;tc--)solve();
}


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];
set<int> S[LM];
vector<int>v[LM];

int C(int x, int y){
    return S[x].find(y)!=S[x].end();
}

void solve(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++)G[i].clear(),v[i].clear();
    for(int i=1; i<n; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
        S[x].insert(y);
        S[y].insert(x);
    }
    int si[LM], Ms=0;
    
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        printf("%d\n",Ms*2-1);
    else if(MsSi==2){
        printf("%d\n",Ms*2-C(v[Ms][0],v[Ms][1])-1);
    }
    else{
        int ws=Ms-1;
        while(v[ws].empty())ws--;
        for(int i:v[ws]){
            if(C(i,v[Ms][0])==0){
                printf("%d\n",Ms+ws-1);
                return;
            }
        }
        printf("%d\n",Ms+ws-2);
    }
}

int main(){
    int tc;
    scanf("%d", &tc);
    for(;tc>0;tc--)solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];
set<int> S[LM];
vector<int>v[LM];

int C(int x, int y){
    return S[x].find(y)!=S[x].end();
}

void solve(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++)G[i].clear(),v[i].clear();
    for(int i=1; i<n; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
        S[x].insert(y);
        S[y].insert(x);
    }
    int si[LM], Ms=0;
    
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        printf("%d\n",Ms*2-1);
    else if(MsSi==2){
        printf("%d\n",Ms*2-C(v[Ms][0],v[Ms][1])-1);
    }
    else{
        int ws=Ms-1;
        while(v[ws].empty())ws--;
        for(int i:v[ws]){
            if(C(i,v[Ms][0])==0){
                printf("%d\n",Ms+ws-1);
                return;
            }
        }
        printf("%d\n",Ms+ws-2);
    }
}

int main(){
    int tc;
    scanf("%d", &tc);
    for(;tc>0;tc--)solve();
}


Submission (verdict: Accepted):
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int LM=200100;
int n;
vector<int>G[LM];
set<int> S[LM];
vector<int>v[LM];

int C(int x, int y){
    return S[x].find(y)!=S[x].end();
}

void solve(){
    scanf("%d",&n);
    for(int i=1; i<=n; i++)G[i].clear(),v[i].clear(),S[i].clear();
    for(int i=1; i<n; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
        S[x].insert(y);
        S[y].insert(x);
    }
    int si[LM], Ms=0;
    
    for(int i=1; i<=n; i++){
        si[i]=G[i].size();
        Ms=max(Ms,si[i]);
        v[si[i]].push_back(i);
    }
    
    int MsSi=v[Ms].size();
    if(MsSi>=3)
        printf("%d\n",Ms*2-1);
    else if(MsSi==2){
        printf("%d\n",Ms*2-C(v[Ms][0],v[Ms][1])-1);
    }
    else{
        int ws=Ms-1;
        while(v[ws].empty())ws--;
        for(int i:v[ws]){
            if(C(i,v[Ms][0])==0){
                printf("%d\n",Ms+ws-1);
                return;
            }
        }
        printf("%d\n",Ms+ws-2);
    }
}

int main(){
    int tc;
    scanf("%d", &tc);
    for(;tc>0;tc--)solve();
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
/*B. Gorilla and the Exam*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
void solve(){
    int n,k;cin >> n >> k;
    map<int,int,less<int>> mp1;
    map<int,int,greater<int>> mp2;
    for(int i = 0; i < n; i++) {
        int x;cin >> x;
        mp1[x]++;
        mp2[x]++;
    }
    int size1 = mp1.size();
    int size2 = size1;
    int tmp = k;
    for(auto t : mp1){
        if(tmp >= t.second){
            tmp -= t.second;
            size1--;
        } 
    }
    tmp = k;
    for(auto t : mp2){
        if(tmp >= t.second){
            tmp -= t.second;
            size2--;
        } 
    }
    cout << max(1,min(size1,size2)) << "\n";
}
int main(){
    int t = 1;cin >> t;
    while(t--){
        solve();
    }
}


Submission (verdict: Accepted):
/*B. Gorilla and the Exam*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
void solve(){
    int n,k;cin >> n >> k;
    map<int,int> mp1;
    for(int i = 0; i < n; i++) {
        int x;cin >> x;
        mp1[x]++;
    }
    vector<int> vc;
    for(auto t : mp1){
        vc.push_back(t.second);   
    }
    sort(vc.begin(),vc.end());
    int size = mp1.size();
    for(int i = 0; i < vc.size(); i++){
        if(k >= vc[i]){
            k -= vc[i];
            size--;
        }
        else break;
    }
    cout << max(1,size) << "\n";
}
int main(){
    int t = 1;cin >> t;
    while(t--){
        solve();
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
/*B. Gorilla and the Exam*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
void solve(){
    int n,k;cin >> n >> k;
    map<int,int> mp1;
    for(int i = 0; i < n; i++) {
        int x;cin >> x;
        mp1[x]++;
    }
    int size = mp1.size();
    for(auto t : mp1){
        if(k >= t.second){
            k -= t.second;
            size--;
        } 
    }
    cout << max(1,size) << "\n";
}
int main(){
    int t = 1;cin >> t;
    while(t--){
        solve();
    }
}

Submission (verdict: Wrong answer on test 3):
/*B. Gorilla and the Exam*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
void solve(){
    int n,k;cin >> n >> k;
    map<int,int,less<int>> mp1;
    map<int,int,greater<int>> mp2;
    for(int i = 0; i < n; i++) {
        int x;cin >> x;
        mp1[x]++;
        mp2[x]++;
    }
    int size1 = mp1.size();
    int size2 = size1;
    int tmp = k;
    for(auto t : mp1){
        if(tmp >= t.second){
            tmp -= t.second;
            size1--;
        } 
    }
    tmp = k;
    for(auto t : mp2){
        if(tmp >= t.second){
            tmp -= t.second;
            size2--;
        } 
    }
    cout << max(1,min(size1,size2)) << "\n";
}
int main(){
    int t = 1;cin >> t;
    while(t--){
        solve();
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
/*B. Gorilla and the Exam*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
void solve(){
    int n,k;cin >> n >> k;
    map<int,int> mp1;
    for(int i = 0; i < n; i++) {
        int x;cin >> x;
        mp1[x]++;
    }
    int size = mp1.size();
    for(auto t : mp1){
        if(k >= t.second){
            k -= t.second;
            size--;
        } 
    }
    cout << max(1,size) << "\n";
}
int main(){
    int t = 1;cin >> t;
    while(t--){
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: Java 21


Submission (verdict: Wrong answer on test 2):
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n-2;i++){
          if(arr[i]<arr[i-1]){
            arr[i+1]=arr[i+1]+(arr[i-1]-arr[i]);
            arr[i]=arr[i-1];
            
          }
        }
        if(arr[n-1]>=arr[n-2]){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}
Problem: 2060D - Subtract Min Sort
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n-2;i++){
          if(arr[i]<arr[i-1]){
            arr[i+1]=arr[i+1]+(arr[i-1]-arr[i]);
            arr[i]=arr[i-1];
            
          }
        }
        if(arr[n-1]>=arr[n-2]){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}

Submission (verdict: Wrong answer on test 2):
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n-1;i++){
          if(arr[i]<arr[i-1]){
            arr[i+1]=arr[i+1]+(arr[i-1]-arr[i]);
            arr[i]=arr[i-1];
            
          }
        }
        if(arr[n-1]>=arr[n-2]){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}
Problem: 2060D - Subtract Min Sort
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n-1;i++){
          if(arr[i]<arr[i-1]){
            arr[i+1]=arr[i+1]+(arr[i-1]-arr[i]);
            arr[i]=arr[i-1];
            
          }
        }
        if(arr[n-1]>=arr[n-2]){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}

Submission (verdict: Accepted):
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner s=new Scanner(System.in);
      int t=s.nextInt();
      while(t-->0){
        int n=s.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
          arr[i]=s.nextInt();
        }
        for(int i=1;i<n;i++){
          int a=Math.min(arr[i],arr[i-1]);
          arr[i-1]-=a;
          arr[i]-=a;
        }
        boolean ans=true;
        for(int i=0;i<n-1;i++){
          if(arr[i]!=0){
            ans=false;
            break;
          }
        }
        if(ans){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
  }
}
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;
typedef long long ll;


int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		map<int,int> m;
		for(int i = 0;i<n;i++){
			int a;
			cin>>a;
			m[a]++;
		}
		vector<int> nums;
		for(auto i :m){
			nums.push_back(i.second);
		}

		sort(nums.begin(),nums.end());
		int ans = nums.size();
		for(int i : nums){
			if(k){
				k-=i;
			}else break;
			ans--;
		}


		cout<<max(ans,1)<<endl;
	}
}


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


int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		map<int,int> m;
		for(int i = 0;i<n;i++){
			int a;
			cin>>a;
			m[a]++;
		}
		vector<int> nums;
		for(auto i :m){
			nums.push_back(i.second);
		}

		sort(nums.begin(),nums.end());
		int ans = nums.size();
		for(int i : nums){
			k-=i;
			if(k<0)break;
			ans--;
		}


		cout<<max(ans,1)<<endl;
	}
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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


int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		map<int,int> m;
		for(int i = 0;i<n;i++){
			int a;
			cin>>a;
			m[a]++;
		}
		vector<int> nums;
		for(auto i :m){
			nums.push_back(i.second);
		}

		sort(nums.begin(),nums.end());
		int ans = nums.size();
		for(int i : nums){
			if(k){
				k-=i;
			}else break;
			ans--;
		}


		cout<<ans<<endl;
	}
}


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


int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		map<int,int> m;
		for(int i = 0;i<n;i++){
			int a;
			cin>>a;
			m[a]++;
		}
		vector<int> nums;
		for(auto i :m){
			nums.push_back(i.second);
		}

		sort(nums.begin(),nums.end());
		int ans = nums.size();
		for(int i : nums){
			if(k){
				k-=i;
			}else break;
			ans--;
		}


		cout<<max(ans,1)<<endl;
	}
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


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


int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		map<int,int> m;
		for(int i = 0;i<n;i++){
			int a;
			cin>>a;
			m[a]++;
		}
		vector<int> nums;
		for(auto i :m){
			nums.push_back(i.second);
		}

		sort(nums.begin(),nums.end());
		int ans = nums.size();
		for(int i : nums){
			if(k){
				k-=i;
			}else break;
			ans--;
		}


		cout<<ans<<endl;
	}
}
Problem: 2050D - Digital string maximization
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.math.*;

import java.util.*;



public class Main {

static Comparator<sr> cmp = new Comparator<>(){

public int compare(sr a1, sr a2){

if(a1.num != a2.num) return a2.num - a1.num;

return a1.idx - a2.idx;

}

};

static int N = (int)2e5 + 5;

static int[] a = new int[N];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- > 0){

PriorityQueue<sr> que = new PriorityQueue<>(cmp);

String s = sc.next();

int len = s.length();

for(int i = 1;i <= len;i++){

a[i] = (int)s.charAt(i - 1) - (int)'0';

que.offer(new sr(a[i], i));

}

while(!que.isEmpty()){

int x = que.peek().num, IDX = que.peek().idx;

que.poll();

if(x != 0 && IDX > 1){

//System.out.println("y");

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

//System.out.println(x + " y " + IDX);

que.offer(new sr(a[IDX] - 1, IDX - 1));

que.offer(new sr(a[IDX - 1], IDX));

que.offer(new sr(a[IDX + 1], IDX + 1));

int t = a[IDX] - 1;

a[IDX] = a[IDX - 1];

a[IDX - 1] = t;

}else{

//System.out.println(x + " n " + IDX);

}

}else{

//System.out.println(x + " n " + IDX);

}

}

for(int i = 1;i <= len;i++){

System.out.print(a[i]);

}

System.out.println();

}

sc.close();

}

}

class sr{

int num, idx;

public sr(int num, int idx){

this.num = num; this.idx = idx;

}

}

Submission (verdict: Wrong answer on test 1):
import java.math.*;

import java.util.*;



public class Main {

static int N = (int)2e5 + 5;

static int[] a = new int[N];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- > 0){

String s = sc.next();

int len = s.length();

for(int i = 1;i <= len;i++){

a[i] = (int)s.charAt(i - 1) - (int)'0';

}

for(int i = 1;i <= len;i++){

int x = a[i], idx = i;

int mx = -1, id = -1;

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

if(a[j] - (j - i) > mx){

mx = a[j] - (j - i);

idx = j;

}

}

for(int j = idx - 1;j >= i;j--){

int t = a[j];

a[j] = a[j + 1] - 1;

a[j + 1] = t;

}

}

for(int i = 1;i <= len;i++){

System.out.print(a[i]);

}

System.out.println();

}

sc.close();

}

}
Problem: 2050D - Digital string maximization
Language: Java 21


Submission (verdict: Wrong answer on test 2):
import java.math.*;

import java.util.*;



public class Main {

static Comparator<sr> cmp = new Comparator<>(){

public int compare(sr a1, sr a2){

if(a1.num != a2.num) return a2.num - a1.num;

return a1.idx - a2.idx;

}

};

static int N = (int)2e5 + 5;

static int[] a = new int[N];

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int T = sc.nextInt();

while(T-- > 0){

PriorityQueue<sr> que = new PriorityQueue<>(cmp);

String s = sc.next();

int len = s.length();

for(int i = 1;i <= len;i++){

a[i] = (int)s.charAt(i - 1) - (int)'0';

que.offer(new sr(a[i], i));

}

while(!que.isEmpty()){

int x = que.peek().num, IDX = que.peek().idx;

que.poll();

if(x != 0 && IDX > 1){

//System.out.println("y");

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

//System.out.println(x + " y " + IDX);

que.offer(new sr(a[IDX] - 1, IDX - 1));

que.offer(new sr(a[IDX - 1], IDX));

que.offer(new sr(a[IDX + 1], IDX + 1));

int t = a[IDX] - 1;

a[IDX] = a[IDX - 1];

a[IDX - 1] = t;

}else{

//System.out.println(x + " n " + IDX);

}

}else{

//System.out.println(x + " n " + IDX);

}

}

for(int i = 1;i <= len;i++){

System.out.print(a[i]);

}

System.out.println();

}

sc.close();

}

}

class sr{

int num, idx;

public sr(int num, int idx){

this.num = num; this.idx = idx;

}

}