ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: Python 3


Submission (verdict: Wrong answer on test 2):
n=int(input())
for i in range(n):
    a,b = list(map(int, input().split()))
    arr = list(map(int, input().strip().split()))
    d = dict.fromkeys(arr, 0)
    for i in arr:
        d[i] += 1
    new_arr = sorted(list(d.values()), reverse=True)
    m = new_arr[0]
    for i in new_arr:
        i=i-m
    if b == 0:
        i = 0
    else:
        for i in range(1,len(new_arr)):
            if new_arr[i] <= b:
                b=b-new_arr[i]
                if b == 0:
                    break
            else:
                b=b-new_arr[i]
                break
    print(len(new_arr) - i)
Problem: 2057B - Gorilla and the Exam
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 12):
n=int(input())
for i in range(n):
    a,b = list(map(int, input().split()))
    arr = list(map(int, input().strip().split()))
    d = dict.fromkeys(arr, 0)
    for i in arr:
        d[i] += 1
    new_arr = sorted(list(d.values()))
    for i in range(len(new_arr)):
        if b == 0:
            break
        if b >= new_arr[i]:
            b = b - new_arr[i]
        else:
            break
    print(len(new_arr) - i)

Submission (verdict: Accepted):
from collections import Counter
n=int(input())
for i in range(n):
    a,b = list(map(int, input().split()))
    arr = Counter(input().split())
    new_arr = sorted(list(arr.values()))
    for i in range(len(new_arr)):
        if b == 0:
            break
        if b >= new_arr[i]:
            b = b - new_arr[i]
        else:
            break
    print(len(new_arr) - i)
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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; cin >> n;
        vector <long long> v(n);
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];;
        }
        bool non_dec = false;
        for (int i = 0; i < n - 1; i++)
        {
            if(v[i] > v[i+1]){
                non_dec = true;
                break;
            }
            else
            {
                v[i + 1] -= v[i];
                v[i] = 0;
            }
        }
        if (non_dec)
        {
            cout << "NO" << endl;
        }
        else{
            cout << "YES" << endl;
        }  
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
// Problem: D. Subtract Min Sort
// Contest: Codeforces - Codeforces Round 998 (Div. 3)
// URL: https://codeforces.com/contest/2060/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve();
int main()
{
	// 提高输入输出效率
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int _; cin >> _;
	while (_--)
		solve();
	return 0;
}

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

	int num = a[0];
	for (int i = 1; i < n; i++)
		if (a[i] != num) {
			if (i == n - 1 &&! (i&1))cout << "YES\n";
			else if (a[i]<num)cout << "NO\n";
			else cout << "YES\n";
			return;
		}
	cout << "YES\n";
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

int main()
{
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector <long long> v(n);
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];;
        }
        bool non_dec = false;
        for (int i = 0; i < n - 1; i++)
        {
            if(v[i] > v[i+1]){
                non_dec = true;
                break;
            }
            else
            {
                v[i + 1] -= v[i];
                v[i] = 0;
            }
        }
        if (non_dec)
        {
            cout << "NO" << endl;
        }
        else{
            cout << "YES" << endl;
        }  
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
// Problem: D. Subtract Min Sort
// Contest: Codeforces - Codeforces Round 998 (Div. 3)
// URL: https://codeforces.com/contest/2060/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve();
int main()
{
	// 提高输入输出效率
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int _; cin >> _;
	while (_--)
		solve();
	return 0;
}

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

	int num = a[0];
	for (int i = 1; i < n; i++)
		if (a[i] != num) {
			if (i == n - 1 &&! (i&1))cout << "YES\n";
			else if (a[i]<num)cout << "NO\n";
			else cout << "YES\n";
			return;
		}
	cout << "YES\n";
}

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

bool isorted(vector<int>arr,int n){
  for(int i=0;i<n-1;i++){

 if(arr[i] > arr[i+1]){
  return 0;
 }

  }

  return 1;
}

void solve(){
   
   int n;
   cin>>n;


   vector<int>arr(n);


   for(int i=0;i<n;i++){
    cin>>arr[i];
   }


   for(int i=0;i<n-1;i++){
       
   if(arr[i] <= arr[i+1]){
    arr[i+1] = arr[i+1]-arr[i];
    arr[i] = 0;
   }

   }

  if(isorted(arr,n))
   cout<<"YES\n";
  
  else cout<<"NO\n";
    
    
}
 
int32_t main() {

    int tt;
    cin>>tt;
    
    while(tt--){
        solve();
    }
 
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
    int n,l,r;
    cin>>n>>l>>r;
    int a[n];
    for (int i = 0 ; i < n ; i++)
        cin>>a[i];

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

    int start = 0 , mid = r-1 , end = r;

    int ans_1 = 0 , ans_2 = 0;

    while(mid>=l-1)
    {
        if(start<l-1)
            ans_1+=min(a[start],a[mid]);
        else
            ans_1+=a[mid];
        if(end<n)
            ans_2+=min(a[end],a[mid]);
        else
            ans_2+=a[mid];
        
        start++;
        mid--;
        end++;

    }

    cout<<min(ans_1,ans_2)<<endl;
   }
}

Submission (verdict: Wrong answer on test 8):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
    int n,l,r;
    cin>>n>>l>>r;
    int a[n];
    for (int i = 0 ; i < n ; i++)
        cin>>a[i];

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

    int start = 0 , mid = r-1 , end = r;

    int ans_1 = 0 , ans_2 = 0;

    while(mid>=l-1)
    {
        if(start<l-1)
            ans_1+=min(a[start],a[mid]);
        else
            ans_1+=a[mid];
        if(end<n)
            ans_2+=min(a[end],a[mid]);
        else
            ans_2+=a[mid];
        
        start++;
        mid--;
        end++;

    }

    cout<<min(ans_1,ans_2)<<endl;
   }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        int a[n];
        for(int i = 0 ; i < n ; i++)
            cin>>a[i];
        int x = r-l+1;
        int lim[x];
        int rem[n-x];
        int e = 0 , f = 0 ;

        for(int i = 0 ; i < n ; i++)
        {
            if(i+1>=l and i+1<=r)
            {
                lim[e] = a[i];
                e++;
            }

            else
            {
                rem[f] = a[i];
                f++;
            }
        }

        sort(lim,lim+x);
        sort(rem,rem+(n-x));

        int p = x-1 , q = 0;

        int res = 0 ;

        while(p>=0 and q<n-x)
        {

            res+=min(lim[p],rem[q]);
            p--;
            q++;
        }

        if(q>=n-x)
        {
            while(p>=0)
                res+=lim[p--];
        }

        cout<<res<<endl;

    }
}

Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
    int n,l,r;
    cin>>n>>l>>r;
    int a[n];
    for (int i = 0 ; i < n ; i++)
        cin>>a[i];

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

    int start = 0 , mid = r-1 , end = r;

    int ans_1 = 0 , ans_2 = 0;

    while(mid>=l-1)
    {
        if(start<l-1)
            ans_1+=min(a[start],a[mid]);
        else
            ans_1+=a[mid];
        if(end<n)
            ans_2+=min(a[end],a[mid]);
        else
            ans_2+=a[mid];
        
        start++;
        mid--;
        end++;

    }

    cout<<min(ans_1,ans_2)<<endl;
   }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
    int n,l,r;
    cin>>n>>l>>r;
    int a[n];
    for (int i = 0 ; i < n ; i++)
        cin>>a[i];

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



    int start = 0 , mid = r-1 , end = r;

    long long int ans_1 = 0 , long long ans_2 = 0;

    while(mid>=l-1)
    {
        if(start<l-1)
            ans_1+=min(a[start],a[mid]);
        else
            ans_1+=a[mid];
        if(end<n)
            ans_2+=min(a[end],a[mid]);
        else
            ans_2+=a[mid];
        
        start++;
        mid--;
        end++;

    }

    cout<<min(ans_1,ans_2)<<endl;
   }
}

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

#include<algorithm>

using namespace std;

int main()

{

   int t;

   cin>>t;

   while(t--)

   {

    int n,l,r;

    cin>>n>>l>>r;

    int a[n];

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

        cin>>a[i];



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

    sort(a,a+l-1);

    sort(a+r,a+n);





    int start = 0 , mid = r-1 , end = r;



    int long long  ans_1 = 0 ,  ans_2 = 0;



    while(mid>=l-1)

    {

        if(start<l-1)

            ans_1+=min(a[start],a[mid]);

        else

            ans_1+=a[mid];

        if(end<n)

            ans_2+=min(a[end],a[mid]);

        else

            ans_2+=a[mid];

        

        start++;

        mid--;

        end++;



    }



    cout<<min(ans_1,ans_2)<<endl;

   }

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

Previous submission (verdict: Wrong answer on test 8):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
    int n,l,r;
    cin>>n>>l>>r;
    int a[n];
    for (int i = 0 ; i < n ; i++)
        cin>>a[i];

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

    int start = 0 , mid = r-1 , end = r;

    int ans_1 = 0 , ans_2 = 0;

    while(mid>=l-1)
    {
        if(start<l-1)
            ans_1+=min(a[start],a[mid]);
        else
            ans_1+=a[mid];
        if(end<n)
            ans_2+=min(a[end],a[mid]);
        else
            ans_2+=a[mid];
        
        start++;
        mid--;
        end++;

    }

    cout<<min(ans_1,ans_2)<<endl;
   }
}

Submission (verdict: Compilation error):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
    int n,l,r;
    cin>>n>>l>>r;
    int a[n];
    for (int i = 0 ; i < n ; i++)
        cin>>a[i];

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



    int start = 0 , mid = r-1 , end = r;

    long long int ans_1 = 0 , long long ans_2 = 0;

    while(mid>=l-1)
    {
        if(start<l-1)
            ans_1+=min(a[start],a[mid]);
        else
            ans_1+=a[mid];
        if(end<n)
            ans_2+=min(a[end],a[mid]);
        else
            ans_2+=a[mid];
        
        start++;
        mid--;
        end++;

    }

    cout<<min(ans_1,ans_2)<<endl;
   }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        int a[n];
        for(int i = 0 ; i < n ; i++)
            cin>>a[i];
        int x = r-l+1;
        int lim[x];
        int rem[n-x];
        int e = 0 , f = 0 ;

        for(int i = 0 ; i < n ; i++)
        {
            if(i+1>=l and i+1<=r)
            {
                lim[e] = a[i];
                e++;
            }

            else
            {
                rem[f] = a[i];
                f++;
            }
        }

        sort(lim,lim+x);
        sort(rem,rem+(n-x));

        int p = x-1 , q = 0;

        int res = 0 ;

        while(p>=0 and q<n-x)
        {

            res+=min(lim[p],rem[q]);
            p--;
            q++;
        }

        if(q>=n-x)
        {
            while(p>=0)
                res+=lim[p--];
        }

        cout<<res<<endl;

    }
}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

typedef long long ll;

#define MII map<int, int>

#define UMII unordered_map<int, int>

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define vi vector<int>

#define vvi vector<vi>

#define qi queue<int>

#define si stack<int>

#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;



int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t;

    cin >> t;

    while(t--){

        int n, x, y;

        cin >> n >> x >> y;

        if(x > y) swap(x, y);

        x--;

        y--;

        vector<int> arr(n);

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

            arr[(x+i) % n] = i % 2;

        }

        if((y - x) % 2 == 0) arr[x] = 2;



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

            cout << arr[i] << " ";

        }

        cout << endl;

    }

    return 0;

}

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

typedef long long ll;

#define MII map<int, int>

#define UMII unordered_map<int, int>

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define vi vector<int>

#define vvi vector<vi>

#define qi queue<int>

#define si stack<int>

#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;



int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t;

    cin >> t;

    while(t--){

        int n, x, y;

        cin >> n >> x >> y;

        if(x > y) swap(x, y);

        x--;

        y--;

        vector<int> arr(n);

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

            arr[(x+i) % n] = i % 2;

        }

        if((y - x) % 2 || (x+n-y) % 2) arr[x] = 2;



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

            cout << arr[i] << " ";

        }

        cout << endl;

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


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

typedef long long ll;

#define MII map<int, int>

#define UMII unordered_map<int, int>

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define vi vector<int>

#define vvi vector<vi>

#define qi queue<int>

#define si stack<int>

#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;



int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t;

    cin >> t;

    while(t--){

        int n, x, y;

        cin >> n >> x >> y;

        if(x > y) swap(x, y);

        x--;

        y--;

        vector<int> arr(n);

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

            arr[(x+i) % n] = i % 2;

        }

        if((y - x) % 2 == 0) arr[x] = 2;



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

            cout << arr[i] << " ";

        }

        cout << endl;

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

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

typedef long long ll;

#define MII map<int, int>

#define UMII unordered_map<int, int>

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define vi vector<int>

#define vvi vector<vi>

#define qi queue<int>

#define si stack<int>

#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;



int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t;

    cin >> t;

    while(t--){

        int n, x, y;

        cin >> n >> x >> y;

        if(x > y) swap(x, y);

        x--;

        y--;

        vector<int> arr(n);

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

            arr[(x+i) % n] = i % 2;

        }

        if((y - x) % 2 || (x+n-y) % 2) arr[x] = 2;



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

            cout << arr[i] << " ";

        }

        cout << endl;

    }

    return 0;

}

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

typedef long long ll;

#define MII map<int, int>

#define UMII unordered_map<int, int>

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define vi vector<int>

#define vvi vector<vi>

#define qi queue<int>

#define si stack<int>

#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;



int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t;

    cin >> t;

    while(t--){

        int n, x, y;

        cin >> n >> x >> y;

        if(x > y) swap(x, y);

        x--;

        y--;

        vector<int> arr(n);

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

            arr[(x+i) % n] = i % 2;

        }

        if((y - x) % 2 == 0 || (x+n-y) % 2 == 0) arr[x] = 2;



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

            cout << arr[i] << " ";

        }

        cout << endl;

    }

    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 20):
// ॐ श्री यीशु
#include<iostream>
#include <bits/stdc++.h>

using namespace std;

bool sortFreq(pair<int, int>p1, pair<int, int>p2) {
    return p1.second<p2.second;
} 


void solve() {
   int n, k;
   cin>>n>>k;
   int arr[n];

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

   int count = 0;

   map<int, int> freq;
   vector<pair<int, int>> freqSorted;

   for(int i=0; i<n; i++) freq[arr[i]]++;

   for(auto it:freq) {
        pair<int, int> p;
        p.first = it.first;
        p.second = it.second;
        freqSorted.push_back(p);
   }
   if(n <= k) {
        cout<<1<<endl;
        return;
   }

   sort(freqSorted.begin(), freqSorted.end(), sortFreq);


   while(k>0) {
        if(freqSorted[0].second>0) {
            if(freqSorted[0].second <= k){
                k -= freqSorted[0].second;
                freqSorted[0].second = 0;
            }
            else break;
        }
        else {
            freqSorted.erase(freqSorted.begin());
        }
   }

   if(freqSorted[0].second==0) freqSorted.erase(freqSorted.begin());

   count = freqSorted.size();
   cout<<count<<endl;
   
}

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

Submission (verdict: Time limit exceeded on test 11):
// ॐ श्री यीशु
#include<iostream>
#include <bits/stdc++.h>

using namespace std;

bool sortFreq(pair<int, int>p1, pair<int, int>p2) {
    return p1.second<p2.second;
} 


void solve() {
   int n, k;
   cin>>n>>k;
   int arr[n];

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

   int count = 0;

   unordered_map<int, int> freq;
   vector<pair<int, int>> freqSorted;

   for(int i=0; i<n; i++) freq[arr[i]]++;

   for(auto it:freq) {
        pair<int, int> p;
        p.first = it.first;
        p.second = it.second;
        freqSorted.push_back(p);
   }
   if(n <= k) {
        cout<<1<<endl;
        return;
   }

   sort(freqSorted.begin(), freqSorted.end(), sortFreq);

    int m = freqSorted.size();
    for(int i=0; i<m-1; i++){
        if(freqSorted[i].second>k) {
            cout<<m-i<<endl;
            return;
        }
        else k -= freqSorted[i].second;
    }

    cout<<1<<endl;
}

int main() {
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 20):
// ॐ श्री यीशु
#include<iostream>
#include <bits/stdc++.h>

using namespace std;

bool sortFreq(pair<int, int>p1, pair<int, int>p2) {
    return p1.second<p2.second;
} 


void solve() {
   int n, k;
   cin>>n>>k;
   int arr[n];

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

   int count = 0;

   map<int, int> freq;
   vector<pair<int, int>> freqSorted;

   for(int i=0; i<n; i++) freq[arr[i]]++;

   for(auto it:freq) {
        pair<int, int> p;
        p.first = it.first;
        p.second = it.second;
        freqSorted.push_back(p);
   }
   if(n <= k) {
        cout<<1<<endl;
        return;
   }

   sort(freqSorted.begin(), freqSorted.end(), sortFreq);


   while(k>0) {
        if(freqSorted[0].second>0) {
            if(freqSorted[0].second <= k){
                k -= freqSorted[0].second;
                freqSorted[0].second = 0;
            }
            else break;
        }
        else {
            freqSorted.erase(freqSorted.begin());
        }
   }

   if(freqSorted[0].second==0) freqSorted.erase(freqSorted.begin());

   count = freqSorted.size();
   cout<<count<<endl;
   
}

int main() {
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
// ॐ श्री यीशु
#include<iostream>
#include <bits/stdc++.h>

using namespace std;

bool sortFreq(pair<int, int>p1, pair<int, int>p2) {
    return p1.second<p2.second;
} 


void solve() {
   int n, k;
   cin>>n>>k;
   int arr[n];

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

   int count = 0;

   unordered_map<int, int> freq;
   vector<pair<int, int>> freqSorted;

   for(int i=0; i<n; i++) freq[arr[i]]++;

   for(auto it:freq) {
        pair<int, int> p;
        p.first = it.first;
        p.second = it.second;
        freqSorted.push_back(p);
   }
   if(n <= k) {
        cout<<1<<endl;
        return;
   }

   sort(freqSorted.begin(), freqSorted.end(), sortFreq);

    int m = freqSorted.size();
    for(int i=0; i<m-1; i++){
        if(freqSorted[i].second>k) {
            cout<<m-i<<endl;
            return;
        }
        else k -= freqSorted[i].second;
    }

    cout<<1<<endl;
}

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

Submission (verdict: Accepted):
// ॐ श्री यीशु
#include<iostream>
#include <bits/stdc++.h>

using namespace std;

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

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

    vector<int> cnt = {1};
    for(int i=1; i<n; i++){
        if(arr[i]==arr[i-1]) cnt.back()++;
        else cnt.emplace_back(1);
    }

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

    int m = cnt.size();
    for(int i=0; i<m-1; i++) {
        if(cnt[i]>k) {
            cout<<m-i<<endl;
            return;
        }
        else k -= cnt[i];
    }
    cout<<1<<endl;

}

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