ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
import math
mod=1000000007
mod1=998244353
inf=10**18+10
t=1
for i in range(t):
    n=int(input())
    l1=list(map(int,input().split()))
    ind=[-1]*(n+1)
    for j in range(n):
        ind[l1[j]]=j
    # print(ind)

    ans=[]
    for j in range(1, j+1):
        ci=ind[j]
        for k in range(1, n+1):
            if j==k:
                continue
            if k>j and ind[k]<ci:
                ans.append([k,j])
            elif k>j and ind[k]>ci:
                ans.append([k,j])
                ans.append([j,k])
    print(len(ans))
    for j in ans:
        print(*j)
    # print(ans)

Submission (verdict: Wrong answer on test 4):
import math
mod=1000000007
mod1=998244353
inf=10**18+10

def swap(l1,x,y):
    a=l1[x]
    l1[x]=l1[y]
    l1[y]=a

t=1
for i in range(t):
    n=int(input())
    l1=list(map(int,input().split()))
    ind=[-1]*(n+1)
    for j in range(n):
        ind[l1[j]]=j

    l2=[j+1 for j in range(n)]
    st=set()

    ans=[]
    flag=1
    while flag:
        flag=0
        x=-1
        y=-1
        for j in range(n-1):
            if ind[l2[j+1]]<ind[l2[j]] and flag==0 and (l2[j], l2[j+1]) not in st:
                flag=1
                x,y=j, j+1
            if ind[l2[j+1]]>ind[l2[j]]:
                if (l2[j], l2[j+1]) not in st:
                    ans.append([l2[j+1],l2[j]])
                    ans.append([l2[j],l2[j+1]])
                    st.add((l2[j+1],l2[j]))
                    st.add((l2[j],l2[j+1]))

        if x!=-1:
            ans.append([l2[y], l2[x]])
            st.add((l2[y], l2[x]))
            # print(l2, ans)
            swap(l2, x, y)

    print(len(ans))
    for j in ans:
        print(*j)
    # print(ans)
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

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

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                arr[i]=0;
            }
            else    break;
        }

        int count=0;

        for(int i=0; i<arr.size(); i++){
            if(arr[i]!=0) 
                count++;
        }  

        if(count==0)
            count++; 

        cout<<count<<"\n";
    }
}

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

void merge(vector<int>& arr, int left, int mid, int right) {
    int n1 = mid - left + 1;
    int n2 = right - mid;
    vector<int> L(n1), R(n2);
    for (int i = 0; i < n1; i++)
        L[i] = arr[left + i];
    for (int i = 0; i < n2; i++)
        R[i] = arr[mid + 1 + i];

    int i = 0, j = 0, k = left;
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        } else {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(vector<int>& arr, int left, int right) {
    if (left < right) {
        int mid = left + (right - left) / 2;
        mergeSort(arr, left, mid);
        mergeSort(arr, mid + 1, right);
        merge(arr, left, mid, right);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

/*         sort(arr.begin(), arr.end());*/        
        mergeSort(arr, 0, arr.size()-1);

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                arr[i]=0;
            }
            else    break;
        }

        int count=0;

        for(int i=0; i<arr.size(); i++){
            if(arr[i]!=0) 
                count++;
        }  

        if(count==0)
            count++; 

        cout<<count<<"\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

void merge(vector<int>& arr, int left, int mid, int right) {
    int n1 = mid - left + 1;
    int n2 = right - mid;
    vector<int> L(n1), R(n2);
    for (int i = 0; i < n1; i++)
        L[i] = arr[left + i];
    for (int i = 0; i < n2; i++)
        R[i] = arr[mid + 1 + i];

    int i = 0, j = 0, k = left;
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        } else {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }
    while (j < n2) {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(vector<int>& arr, int left, int right) {
    if (left < right) {
        int mid = left + (right - left) / 2;
        mergeSort(arr, left, mid);
        mergeSort(arr, mid + 1, right);
        merge(arr, left, mid, right);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

/*         sort(arr.begin(), arr.end());*/        
        mergeSort(arr, 0, arr.size()-1);

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                arr[i]=0;
            }
            else    break;
        }

        int count=0;

        for(int i=0; i<arr.size(); i++){
            if(arr[i]!=0) 
                count++;
        }  

        if(count==0)
            count++; 

        cout<<count<<"\n";
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

        sort(arr.begin(), arr.end());  
        int count=arr.size();

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                count--;
            }
            else    break;
        }
        if(count==0)    count++;

        cout<<count<<"\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

        sort(arr.begin(), arr.end());  
        int count=arr.size();

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                count--;
            }
            else    break;
        }
        if(count==0)    count++;

        cout<<count<<"\n";
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

        sort(arr.begin(), arr.end());  
        int count=arr.size();

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                count--;
            }
            else    break;
        }
        if(count==0)    count++;

        cout<<count<<"\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<pair<int, int>> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(make_pair(i->second, i->first));

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

        for(int i=0; i<arr.size(); i++){
            if(arr[i].first<=k){
                k-=arr[i].first;
                arr[i].first=0;
            }
            else    break;
        }

        int count=0;

        for(int i=0; i<arr.size(); i++){
            if(arr[i].first!=0) 
                count++;
        }  

        if(count==0)
            count++; 

        cout<<count<<"\n";

        /* for(auto it=mp.begin(); it!=mp.end(); it++){
            if(it->second<=k){
                k-=it->second;
                mp.erase(it);
            }
            else{

            }
        } */
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<int> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(i->second);

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

        for(int i=0; i<arr.size(); i++){
            if(arr[i]<=k){
                k-=arr[i];
                arr[i]=0;
            }
            else    break;
        }

        int count=0;

        for(int i=0; i<arr.size(); i++){
            if(arr[i]!=0) 
                count++;
        }  

        if(count==0)
            count++; 

        cout<<count<<"\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        unordered_map<int, int> mp;
        vector<pair<int, int>> arr;
        for(int i=0; i<n; i++){
            int x;
            cin>>x;
            mp[x]++;
        }

        for(auto i=mp.begin(); i!=mp.end(); i++)
            arr.pb(make_pair(i->second, i->first));

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

        for(int i=0; i<arr.size(); i++){
            if(arr[i].first<=k){
                k-=arr[i].first;
                arr[i].first=0;
            }
            else    break;
        }

        int count=0;

        for(int i=0; i<arr.size(); i++){
            if(arr[i].first!=0) 
                count++;
        }  

        if(count==0)
            count++; 

        cout<<count<<"\n";

        /* for(auto it=mp.begin(); it!=mp.end(); it++){
            if(it->second<=k){
                k-=it->second;
                mp.erase(it);
            }
            else{

            }
        } */
    }
}
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;

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

/*
 	map <int, int> m;
	int n;
	cin >> n;
	while (n--) {
		int k;
		cin >> k;
		m[k]++;
		if (m.find(k) != m.end()) {
		 	cout << m[k] << endl;
		}
	}
	m.clear();
	for (auto it: m) {
	 	cout << it.first << " " << it.second << endl;
	}
 	void - return;

	int min3(int &a, int b, int c) {
	int res = min(a, min(b, c));
	return res;
 	}

int f(int n) {
	cout << "f(" << n << ") start\n";
	if (n == 1) return 1; // exit
 	int res = n * f(n - 1);
 	cout << "f(" << n << ") end\n";
 	return res;
}

int a[100005], b[100005], w;         

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	cin >> q;
	for (int i = 1; i <= q; i++) {
		int x;
		cin >> x;
		if (x < a[1]) cout << 0 << endl;
		else {
			int l = 1, r = n + 1;
        	while (r - l > 1) {
        		int mid = (l + r) / 2;
       			if (x >= a[mid]) l = mid;
        		else r = mid;
     		}	
     		cout << l << endl;
     	}  
	}            
	ok = ok && (x == 5 || x == 7);
	return 0;
}
*/
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    int n;
    cin>>n;
    vector<int> a(n+10);
    int x=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];        
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        int sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(int i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    long long n;
    cin>>n;
    vector<long long> a(n+10);
    int x=0;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];        
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        int sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(long long i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	long long t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    long long n;
    cin>>n;
    vector<long long> a(n+10);
    long long x=0;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];        
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        long long sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(long long i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	long long t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    int n;
    cin>>n;
    vector<int> a(n+10);
    int x=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];        
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        int sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(int i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    long long n;
    cin>>n;
    vector<long long> a(n+10);
    int x=0;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];        
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        int sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(long long i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	long long t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    long long n;
    cin>>n;
    vector<long long> a(n+10);
    int x=0;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];        
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        int sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(long long i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	long long t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    long long n;
    cin>>n;
    vector<long long> a(n+10);
    int x=0;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
        x+=a[i];        
    }
    if(n==1){
        cout<<a[1]<<"\n";return;
    }
    int t=n;
    while(t){
        int sum=0;
        sum=a[t]-a[1];
        x=max(abs(sum),x);
        t--;
        for(long long i=1;i<=t;i++){
            a[i]=a[i+1]-a[i];
        }
    }
    cout<<x<<"\n";
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	long long t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
#define NSD ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define yes cout<<"DA"<<endl;
#define no cout<<"NET"<<endl;
using namespace std;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }

ll binaryexpoI(ll a, ll b){
    ll ans = 1;
    while (b)
    {
        if (b & 1)
        {
            ans = ans * a;
        }
        a = a * a;
        b >>= 1;
    }
    return ans;
}


int main()
{
    ll t;
    cin>>t;
    while (t--)
    {
		ll n,k;
		cin>>n>>k;
		ll a[n];
		unordered_map<ll,ll> m;
		for (int i = 0; i < n; i++)
		{
			cin>>a[i];
			m[a[i]]++;
		}
		vector<ll> v;
		for(auto x:m){
			v.push_back(x.second);
		}
		sort(v.begin(),v.end());
		for (int i = 1; i < v.size(); i++)
		{
			v[i]+=v[i-1];
		}
		ll i=0;
		for (i = 0; i < v.size(); i++)
		{
			// cout<<v[i]<<endl;
			if(v[i]>k){
				break;
			}
		}
		if(k>=n){
			cout<<1<<endl;
		}
		else{
			cout<<v.size()-i<<endl;
		}
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
#define NSD ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define yes cout<<"DA"<<endl;
#define no cout<<"NET"<<endl;
using namespace std;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }

ll binaryexpoI(ll a, ll b){
    ll ans = 1;
    while (b)
    {
        if (b & 1)
        {
            ans = ans * a;
        }
        a = a * a;
        b >>= 1;
    }
    return ans;
}


int main()
{
    ll t;
    cin>>t;
    while (t--)
    {
		ll n,k;
		cin>>n>>k;
		ll a[n];
		unordered_map<ll,ll> m;
		for (int i = 0; i < n; i++)
		{
			cin>>a[i];
			m[a[i]]++;
		}
		vector<ll> v;
		for(auto x:m){
			v.push_back(x.second);
		}
		sort(v.begin(),v.end());
		for (int i = 1; i < v.size(); i++)
		{
			v[i]+=v[i-1];
		}
		ll i=0;
		for (i = 0; i < v.size(); i++)
		{
			// cout<<v[i]<<endl;
			if(v[i]>k){
				break;
			}
		}
		if(k>=n){
			cout<<1<<endl;
		}
		else{
			cout<<v.size()-i<<endl;
		}
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
#define NSD ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define yes cout<<"DA"<<endl;
#define no cout<<"NET"<<endl;
using namespace std;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }

ll binaryexpoI(ll a, ll b){
    ll ans = 1;
    while (b)
    {
        if (b & 1)
        {
            ans = ans * a;
        }
        a = a * a;
        b >>= 1;
    }
    return ans;
}


int main()
{
    ll t;
    cin>>t;
    while (t--)
    {
		ll n,k;
		cin>>n>>k;
		ll a[n];
		unordered_map<ll,ll> m;
		for (int i = 0; i < n; i++)
		{
			cin>>a[i];
			m[a[i]]++;
		}
		if(k>=n){
			cout<<1<<endl;
			continue;
		}
		vector<ll> v;
		for(auto x:m){
			v.push_back(x.second);
		}
		sort(v.begin(),v.end());
		ll i=0;
		for (i = 0; i < v.size() && k>0; i++)
		{
			k-=v[i];
		}
		if(k==0){
			cout<<v.size()-i<<endl;
		}
		else{
			cout<<v.size()-i+1<<endl;
		}

    }
    return 0;
}