ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    string s;
    cin >> s;
    bool check = true;
    while (check)
    {
      int flag = 0;
      for (int i = 0; i < s.size() - 1; i++)
      {
        if (s[i] - '0' < s[i + 1] - '0' - 1)
        {
          swap(s[i], s[i + 1]);
          int temp = (s[i] - '0' - 1);
          s[i] = temp + '0';
          flag = 1;
          break;
        }
      }
      if (flag == 1)
      {
        check = true;
      }
      else
      {
        check = false;
      }
    }
    cout << s << endl;
  }
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    string s;
    cin >> s;
    bool check = true;
    while (check)
    {
      int flag = 0;
      for (int i = 0; i < s.size() - 1; i++)
      {
        if (s[i] - '0' < s[i + 1] - '0' - 1)
        {
          swap(s[i], s[i + 1]);
          int temp = (s[i] - '0' - 1);
          s[i] = temp + '0';
          flag = 1;
          break;
        }
      }
      if (flag == 1)
      {
        check = true;
      }
      else
      {
        check = false;
      }
    }
    cout << s << endl;
  }
}

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

int main()
{
    ios::sync_with_stdio(false); // I/O ফাস্ট করার জন্য
    cin.tie(0); // cin & cout এর মধ্যে ফ্লাশিং বন্ধ করে আরও দ্রুত করে

    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        bool check = true;
        while (check)
        {
            int flag = 0;
            for (int i = 0; i < s.size() - 1; i++)
            {
                if (s[i] - '0' < s[i + 1] - '0' - 1)
                {
                    swap(s[i], s[i + 1]);
                    int temp = (s[i] - '0' - 1);
                    s[i] = temp + '0';
                    flag = 1;
                    break;
                }
            }
            if (flag == 1)
            {
                check = true;
            }
            else
            {
                check = false;
            }
        }
        cout << s << '\n'; // endl এর বদলে '\n' ব্যবহার করা আরও দ্রুত
    }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

    using namespace std;



    string c;



    int solve(string a, string b){

        int arr[a.length()+1][b.length()+1];

        for(int i=0; i<=a.length(); i++){

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

                if(i == 0 && j == 0) arr[i][j] = 0;

                else if (i == 0 && j != 0){

                    if(b[j-1] == c[j-1]) arr[i][j] = arr[i][j-1];

                    else arr[i][j] = arr[i][j-1]+1;

                } else if(i != 0 && j == 0){

                    if(a[i-1] == c[i-1]) arr[i][j] = arr[i-1][j];

                    else arr[i][j] = arr[i-1][j]+1;

                } else{

                    int ans_1, ans_2;

                    if(a[i-1] == c[i+j-2]) ans_1 = arr[i-1][j];

                    else ans_1 = arr[i-1][j]+1;

                    if(b[j-1] == c[i+j-2]) ans_2 = arr[i][j-1];

                    else ans_2 = arr[i][j-1]+1;

                    arr[i][j] = min(ans_1,ans_2);

                }

            }

        }



        return arr[a.length()][b.length()];

    }



    int main(){



        int t; cin >> t;

        while(t--){

            string a,b; cin >> a >> b >> c;

            cout << solve(a,b) << endl;

        }



        return 0;

    }

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

    using namespace std;



    string c;



    int solve(string a, string b){

        int arr[a.length()+1][b.length()+1];

        for(int i=0; i<=a.length(); i++){

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

                if(i == 0 && j == 0) arr[i][j] = 0;

                else if (i == 0 && j != 0){

                    if(b[j-1] == c[j-1]) arr[i][j] = arr[i][j-1];

                    else arr[i][j] = arr[i][j-1]+1;

                } else if(i != 0 && j == 0){

                    if(a[i-1] == c[i-1]) arr[i][j] = arr[i-1][j];

                    else arr[i][j] = arr[i-1][j]+1;

                } else{

                    int ans_1, ans_2;

                    if(a[i-1] == c[i+j-1]) ans_1 = arr[i-1][j];

                    else ans_1 = arr[i-1][j]+1;

                    if(b[j-1] == c[i+j-1]) ans_2 = arr[i][j-1];

                    else ans_2 = arr[i][j-1]+1;

                    arr[i][j] = min(ans_1,ans_2);

                }

            }

        }



        return arr[a.length()][b.length()];

    }



    int main(){



        int t; cin >> t;

        while(t--){

            string a,b; cin >> a >> b >> c;

            cout << solve(a,b) << endl;

        }



        return 0;

    }
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

using namespace std;



int solve(string a, string b, string c){

    int arr[a.length()+1][b.length()+1];

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

        for(int j=0; j<=b.size(); j++){

            if(i == 0 && j == 0) arr[i][j] = 0;

            else if (i == 0 && j != 0){

                if(b[j-1] == c[j-1]) arr[i][j] = arr[i][j-1];

                else arr[i][j] = arr[i][j-1]+1;

            } else if(i != 0 && j == 0){

                if(a[i-1] == c[i-1]) arr[i][j] = arr[i-1][j];

                else arr[i][j] = arr[i-1][j]+1;

            } else{

                int ans_1, ans_2;

                if(a[i-1] == c[i+j-2]) ans_1 = arr[i-1][j];

                else ans_1 = arr[i-1][j]+1;

                if(b[j-1] == c[i+j-2]) ans_2 = arr[i][j-1];

                else ans_2 = arr[i][j-1]+1;

                arr[i][j] = min(ans_1,ans_2);

            }

        }

    }



    return arr[0][1];

}



int main(){



    int t; cin >> t;

    while(t--){

        string a,b,c; cin >> a >> b >> c;

        cout << solve(a,b,c) << endl;

    }



    return 0;

}

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

    using namespace std;



    string c;



    int solve(string a, string b){

        int arr[a.length()+1][b.length()+1];

        for(int i=0; i<=a.length(); i++){

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

                if(i == 0 && j == 0) arr[i][j] = 0;

                else if (i == 0 && j != 0){

                    if(b[j-1] == c[j-1]) arr[i][j] = arr[i][j-1];

                    else arr[i][j] = arr[i][j-1]+1;

                } else if(i != 0 && j == 0){

                    if(a[i-1] == c[i-1]) arr[i][j] = arr[i-1][j];

                    else arr[i][j] = arr[i-1][j]+1;

                } else{

                    int ans_1, ans_2;

                    if(a[i-1] == c[i+j-2]) ans_1 = arr[i-1][j];

                    else ans_1 = arr[i-1][j]+1;

                    if(b[j-1] == c[i+j-2]) ans_2 = arr[i][j-1];

                    else ans_2 = arr[i][j-1]+1;

                    arr[i][j] = min(ans_1,ans_2);

                }

            }

        }



        return arr[a.length()][b.length()];

    }



    int main(){



        int t; cin >> t;

        while(t--){

            string a,b; cin >> a >> b >> c;

            cout << solve(a,b) << endl;

        }



        return 0;

    }
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

using namespace std;



int solve(string a, string b, string c){

    int arr[a.length()][b.length()];

    for(int i=0; i<a.length(); i++){

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

            int ans_1=a.length()+b.length(), ans_2=a.length()+b.length();

            if(i != 0 and a[i] == c[i+j]) ans_1 = arr[i-1][j];

            else ans_1 = arr[i-1][j]+1;

            if(j != 0 and b[j] == c[i+j]) ans_2 = arr[i][j-1];

            else ans_2 = arr[i][j-1]+1;

            if(i != 0 and j != 0) arr[i][j] = min(ans_1,ans_2);

        }

    }

    return arr[a.length()-1][b.length()-1];

}



int main(){



    int t; cin >> t;

    while(t--){

        string a,b,c; cin >> a >> b >> c;

        cout << solve(a,b,c) << endl;

    }



    return 0;

}

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

using namespace std;



int solve(string a, string b, string c){

    int arr[a.length()+1][b.length()+1];

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

        for(int j=0; j<=b.size(); j++){

            if(i == 0 && j == 0) arr[i][j] = 0;

            else if (i == 0 && j != 0){

                if(b[j-1] == c[j-1]) arr[i][j] = arr[i][j-1];

                else arr[i][j] = arr[i][j-1]+1;

            } else if(i != 0 && j == 0){

                if(a[i-1] == c[i-1]) arr[i][j] = arr[i-1][j];

                else arr[i][j] = arr[i-1][j]+1;

            } else{

                int ans_1, ans_2;

                if(a[i-1] == c[i+j-2]) ans_1 = arr[i-1][j];

                else ans_1 = arr[i-1][j]+1;

                if(b[j-1] == c[i+j-2]) ans_2 = arr[i][j-1];

                else ans_2 = arr[i][j-1]+1;

                arr[i][j] = min(ans_1,ans_2);

            }

        }

    }



    return arr[0][1];

}



int main(){



    int t; cin >> t;

    while(t--){

        string a,b,c; cin >> a >> b >> c;

        cout << solve(a,b,c) << endl;

    }



    return 0;

}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


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

using namespace std;



int solve(string a, string b, string c){

    int arr[a.length()][b.length()];

    for(int i=0; i<a.length(); i++){

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

            int ans_1=a.length()+b.length(), ans_2=a.length()+b.length();

            if(i != 0 and a[i] == c[i+j]) ans_1 = arr[i-1][j];

            else ans_1 = arr[i-1][j]+1;

            if(j != 0 and b[j] == c[i+j]) ans_2 = arr[i][j-1];

            else ans_2 = arr[i][j-1]+1;

            if(i != 0 and j != 0) arr[i][j] = min(ans_1,ans_2);

        }

    }

    return arr[a.length()-1][b.length()-1];

}



int main(){



    int t; cin >> t;

    while(t--){

        string a,b,c; cin >> a >> b >> c;

        cout << solve(a,b,c) << endl;

    }



    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(){
	long long t; cin>>t;
	while(t--){
		long long n, l, r; cin>>n>>l>>r;
		vector<long long> v(n);
		for(long long i=0;i<n;i++){
			cin>>v[i];
		}
		sort(v.begin(),v.end());
		long long len = r-l+1;
		long long ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v[i];
		}
		cout<<ans <<endl;
	}
	return 0;
}

Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long t; cin>>t;
	while(t--){
		long long n, l, r; cin>>n>>l>>r;
		vector<long long> v1, v2;
		for(long long i=0;i<n;i++){
			int x; cin >>x;
			if(i<=r-1){
				v1.push_back(x);
			}
			if(i>=l-1){
				v2.push_back(x);
			}
		}
		sort(v1.begin(),v1.end());
		sort(v2.begin(),v2.end());
		long long len = r-l+1;
		long long res = INT_MAX;
		long long ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v1[i];
		}
		res = min(res,ans);
		ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v2[i];
		}
		res = min(res,ans);
		cout<<res <<endl;
	}
	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;

		vector<int> v(n);

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

			cin>>v[i];

		}

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

		int len = r-l+1;

		int ans = 0;

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

			ans+=v[i];

		}

		cout<<ans <<endl;

	}

	return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long t; cin>>t;
	while(t--){
		long long n, l, r; cin>>n>>l>>r;
		vector<long long> v(n);
		for(long long i=0;i<n;i++){
			cin>>v[i];
		}
		sort(v.begin(),v.end());
		long long len = r-l+1;
		long long ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v[i];
		}
		cout<<ans <<endl;
	}
	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;

		vector<int> v(n);

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

			cin>>v[i];

		}

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

		int len = r-l+1;

		int ans = 0;

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

			ans+=v[i];

		}

		cout<<ans <<endl;

	}

	return 0;

}
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(){
	long long t; cin>>t;
	while(t--){
		long long n, l, r; cin>>n>>l>>r;
		vector<long long> v1, v2;
		for(long long i=0;i<n;i++){
			int x; cin >>x;
			if(i<=r-1){
				v1.push_back(x);
			}
			if(i>=l-1){
				v2.push_back(x);
			}
		}
		sort(v1.begin(),v1.end());
		sort(v2.begin(),v2.end());
		long long len = r-l+1;
		long long res = INT_MAX;
		long long ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v1[i];
		}
		res = min(res,ans);
		ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v2[i];
		}
		res = min(res,ans);
		cout<<res <<endl;
	}
	return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long t; cin>>t;
	while(t--){
		long long n, l, r; cin>>n>>l>>r;
		vector<long long> v1, v2;
		for(long long i=0;i<n;i++){
			int x; cin >>x;
			if(i<=r-1){
				v1.push_back(x);
			}
			if(i>=l-1){
				v2.push_back(x);
			}
		}
		sort(v1.begin(),v1.end());
		sort(v2.begin(),v2.end());
		long long len = r-l+1;
		long long res = LLONG_MAX;
		long long ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v1[i];
		}
		res = min(res,ans);
		ans = 0;
		for(long long i=0;i<len;i++){
			ans+=v2[i];
		}
		res = min(res,ans);
		cout<<res <<endl;
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
      int n,k;
      cin>>n>>k;
      vector<int>a(n);
      unordered_map<int,int>freq;
      for(int i=0;i<n;i++){
          cin>>a[i];;
          freq[a[i]]++;
      }
      int UniqueV = freq.size();
      if (k >= UniqueV - 1) {
            cout << 1 << endl;
        } else {
            cout << UniqueV - k << endl;
        }
    }

    return 0;
}


Submission (verdict: Time limit exceeded on test 14):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    unordered_map<int, int> freq_map;
    for (int i = 0; i < n; i++) {
        freq_map[a[i]]++;
    }

    vector<int> freq_count;
    for (const auto& entry : freq_map) {
        freq_count.push_back(entry.second);
    }

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

    int m = freq_count.size();
    for (int i = 0; i < m - 1; i++) {
        if (freq_count[i] > k) {
            cout << m - i << "\n";
            return;
        }
        k -= freq_count[i];
    }

    cout << 1 << "\n";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    unordered_map<int, int> freq_map;
    for (int i = 0; i < n; i++) {
        freq_map[a[i]]++;
    }

    vector<int> freq_count;
    for (const auto& entry : freq_map) {
        freq_count.push_back(entry.second);
    }

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

    int m = freq_count.size();
    for (int i = 0; i < m - 1; i++) {
        if (freq_count[i] > k) {
            cout << m - i << "\n";
            return;
        }
        k -= freq_count[i];
    }

    cout << 1 << "\n";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    vector<int> freq_count;
    int count = 1;

    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            count++;
        } else {
            freq_count.push_back(count);
            count = 1;
        }
    }
    freq_count.push_back(count);  
    sort(freq_count.begin(), freq_count.end());

    int distinct_count = freq_count.size();
    for (int i = 0; i < distinct_count - 1; i++) {
        if (freq_count[i] > k) {
            cout << distinct_count - i << "\n";
            return;
        }
        k -= freq_count[i];
    }

    cout << 1 << "\n";
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
      int n,k;
      cin>>n>>k;
      
      vector<int>a(n);
      unordered_map<int,int>freq;
      
      for(int i=0;i<n;i++){
          cin>>a[i];;
          freq[a[i]]++;
      }
      
      vector<int>freqs;
      for(auto& [key,value] : freq){
          freqs.push_back(value);
      }
      sort(freqs.begin(),freqs.end());
      
      int UniqueV = freqs.size();
      for(int f : freqs){
          if(k>=f){
              k -= f;
              UniqueV--;
          }
          else
            break;
      }
      if(UniqueV == k)
      cout<<1<<endl;
      else
      cout<<UniqueV<<endl;
    }

    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
      int n,k;
      cin>>n>>k;
      vector<int>a(n);
      unordered_map<int,int>freq;
      for(int i=0;i<n;i++){
          cin>>a[i];;
          freq[a[i]]++;
      }
      int UniqueV = freq.size();
      if (k >= UniqueV - 1) {
            cout << 1 << endl;
        } else {
            cout << UniqueV - k << endl;
        }
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
      int n,k;
      cin>>n>>k;
      
      vector<int>a(n);
      unordered_map<int,int>freq;
      
      for(int i=0;i<n;i++){
          cin>>a[i];;
          freq[a[i]]++;
      }
      
      vector<int>freqs;
      for(auto& [key,value] : freq){
          freqs.push_back(value);
      }
      sort(freqs.begin(),freqs.end());
      
      int UniqueV = freqs.size();
      for(int f : freqs){
          if(k>=f){
              k -= f;
              UniqueV--;
          }
          else
            break;
      }
      if(UniqueV == k)
      cout<<1<<endl;
      else
      cout<<UniqueV<<endl;
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;




void solve(){
	int l,r;
	cin>>l>>r;
	int k= 31 - __builtin_clz(r^l);
	int a= l | (1<<k), b=a-1, c = ((b==l)? r: l);
	cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}


Submission (verdict: Accepted):
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;




void solve(){
	int l,r;
	cin>>l>>r;
	int k= 31 - __builtin_clz(r^l);
	int a= l | ((1<<k)-1), b=a+1, c = ((a==l)? r: l);
	cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
	int t;
	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):
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ll long long
#define lld long double
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tc    \
    int t;    \
    cin >> t; \
    while (t--)
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

void solve()
{
    int n, k;
    cin >> n >> k;
    unordered_map<int, int> m1;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        m1[a]++;
    }
    vector<int> v1;
    for (auto it : m1)
    {
        v1.push_back(it.second);
    }
    sort(v1.begin(), v1.end());
    // cout << v1[0] << " ";
    for (int i = 1; i < v1.size(); i++)
    {
        // cout << v1[i] << " ";
        v1[i] += v1[i - 1];
    }
    // cout << endl;
    int i = 0;
    while (i < n && k >= v1[i])
        i++;
    if (i == n)
        cout << 1 << endl;
    else
        cout << v1.size() - i << endl;
}

int main()
{
    IOS tc
    {
        solve();
    }
}

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

#define endl '\n'
#define ll long long
#define lld long double
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tc    \
    int t;    \
    cin >> t; \
    while (t--)
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

void solve()
{
    int n, k;
    cin >> n >> k;
    unordered_map<int, int> m1;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        m1[a]++;
    }
    vector<int> v1;
    for (auto it : m1)
    {
        v1.push_back(it.second);
    }
    sort(v1.begin(), v1.end());
    // cout << v1[0] << " ";
    for (int i = 1; i < v1.size(); i++)
    {
        // cout << v1[i] << " ";
        v1[i] += v1[i - 1];
    }
    // cout << endl;
    int i = 0;
    while (i < v1.size() && k >= v1[i])
        i++;
    if (i == v1.size())
        cout << 1 << endl;
    else
        cout << v1.size() - i << endl;
}

int main()
{
    IOS tc
    {
        solve();
    }
}