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

#define int long long
#define dub long double
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef unordered_map<int,int> umap;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(a) a.begin(),a.end()
#define endl '\n'
#define INF 2147483647
//#define INF 9223372036854775807
#define null '\0'
const int N = 1e5 + 10, Mod = 1e9 + 7;
int n,m,k;
void solve(){
    cin >> n >> k;
    vint a(n);
    rep(i,0,n) cin >> a[i];
    map<int,int> mp;
    rep(i,0,n) mp[a[i]] ++;
    int ans = 0;
    for(auto i : mp) {
        if(i.second <= k) k-= i.second;
        else ans++;
    }
    cout << max(1LL,ans) << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_n = 1;
    cin>>test_n;
    for(int t_c = 1;t_c <= test_n;t_c ++){
        solve();
    }
    return 0;
}

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

#define int long long
#define dub long double
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef unordered_map<int,int> umap;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(a) a.begin(),a.end()
#define endl '\n'
#define INF 2147483647
//#define INF 9223372036854775807
#define null '\0'
const int N = 1e5 + 10, Mod = 1e9 + 7;
int n,m,k;
void solve(){
    cin >> n >> k;
    vint a(n);
    rep(i,0,n) cin >> a[i];
    map<int,int> mp;
    rep(i,0,n) mp[a[i]] ++;
    int ans = 0;
    vii v;
    for(auto i : mp) {
        v.push_back({i.second , i.first});
        ans++;
    }
    sort(all(v));
    for(auto i : v) {
        if(i.first <= k) k -= i.first , ans--;
    }
    cout << max(1LL,ans) << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_n = 1;
    cin>>test_n;
    for(int t_c = 1;t_c <= test_n;t_c ++){
        solve();
    }
    return 0;
}

Answer: 2


 #include <bits/stdc++.h>

using namespace std;

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

#include <bits/stdc++.h>

using namespace std;

int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,k;
		cin>>n>>k;
		vector<int> v;
		set<int> st;
		for(int i=0;i<n;i++) {
			 int x;cin>>x;
			 v.push_back(x);
			 st.insert(x);
		}
		if(k==0) {
			cout<<st.size()<<endl;
		}
		else if(k==n) {
			cout<<1<<endl;
		}
		else {
			sort(v.begin(),v.end());
			int k1=k;
			set<int> uqp;
			int unqp=0;
			if(v[k1-1]==v[k1]) {unqp--;}
			while(k1>0) {
				uqp.insert(v[k1-1]); k1--;
			}
			unqp+=uqp.size();
			k1=n-k;
			set<int> uqs;
			int unqs=0;
			if(v[k1+1]==v[k1]) {unqs--;}
			while(k1<n) {
				uqs.insert(v[k1]); k1++;
			}
			unqs+=uqs.size();
			cout<<st.size()-(max(unqp,unqs))<<endl;
		}
		t--;
	}
}

Answer: 1


#include <iostream>
#include <stdio.h>
#include <string>
#include <stack>
#include <deque>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <climits>
#include <cstdio>
#include <cmath>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void flash(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

#define all(a)   a.begin(),a.end()
#define all_r(a)   a.rbegin(),a.rend()

// bool is_suffix(string a, string b)
// {
//     reverse(a.begin(), a.end());
//     reverse(b.begin(), b.end());

//     for(int i = 0; i < b.size(); i++)
//     {
//         if(a[i] != b[i])
//             return false;
//     }

//     return true;
// }

// bool ispalin(vector<int>& v)
// {
//     for(int i = 0; i < v.size() / 2; i++)
//     {
//         if(v[i] != v[v.size() - i - 1])
//             return false;
//     }

//     return true;
// }

int main(void)
{
    flash();

    int t;
    cin>>t;

    while(t--)
    {
        int n, k;
        cin>>n>>k;

        vector<ll> v(n);
        for(int i = 0; i < n; i++)
            cin>>v[i];

        sort(all(v));

        int mx = 0;
        int cnt = 1;
        for(int i = 1; i < n; i++)
        {
            if(v[i] == v[i-1])
                cnt++;
            else
            {
                mx = max(cnt, mx);
                cnt = 1;
            }
        }

        for(int i = 0; i < n && k > 0; i++)
        {
            if(v[i] != mx)
            {
                v[i] = mx;
                k--;
            }
        }

        unordered_set<ll> s;
        for(int i = 0; i < n; i++)
        {
            s.insert(v[i]);
        }

        cout<<s.size()<<'\n';
    }
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <stack>
#include <deque>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <climits>
#include <cstdio>
#include <cmath>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void flash(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

#define all(a)   a.begin(),a.end()
#define all_r(a)   a.rbegin(),a.rend()

// bool is_suffix(string a, string b)
// {
//     reverse(a.begin(), a.end());
//     reverse(b.begin(), b.end());

//     for(int i = 0; i < b.size(); i++)
//     {
//         if(a[i] != b[i])
//             return false;
//     }

//     return true;
// }

// bool ispalin(vector<int>& v)
// {
//     for(int i = 0; i < v.size() / 2; i++)
//     {
//         if(v[i] != v[v.size() - i - 1])
//             return false;
//     }

//     return true;
// }

int main(void)
{
    flash();

    int t;
    cin>>t;

    while(t--)
    {
        int n, k;
        cin>>n>>k;

        vector<ll> v(n);
        for(int i = 0; i < n; i++)
            cin>>v[i];

        sort(all(v));

        vector<ll> freq = {1};
        for(int i = 1; i < n; i++)
        {
            if(v[i] == v[i-1])
                freq.back()++;
            else
                freq.push_back(1);
        }

        sort(all(freq));

        bool is = false;
        for(int i = 0; i < freq.size(); i++)
        {
            if(freq[i] > k)
            {
                cout<<freq.size() - i<<'\n';
                is = true;
                break;
            }

            k -= freq[i];
        }

        if(!is)
            cout<<1<<'\n';
    }
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;cin>>t;
    while(t--){
        long long n,k;cin>>n>>k;
        vector<long long>v(n);
        map<long long,long long>m;
        for(long long i=0;i<n;i++){cin>>v[i];m[v[i]]++;}
        vector<long long>a;
        for(auto& [x,y]:m){a.push_back(y);}
        sort(a.begin(),a.end());
        long long ans=a.size();
        for(long long i=0;i<a.size()-1;i++){if(k>=a[i]){k-=a[i];ans--;}}
        cout<<ans<<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;cin>>t;
    while(t--){
        long long n,k;cin>>n>>k;
        vector<long long>v(n);
        map<long long,long long>m;
        for(long long i=0;i<n;i++){cin>>v[i];m[v[i]]++;}
        vector<long long>a;
        for(auto& [x,y]:m){a.push_back(y);}
        sort(a.begin(),a.end());
        long long ans=a.size();
        for(long long i=0;i<a.size();i++){if(k>=a[i]){k-=a[i];ans--;}}
        cout<<ans<<endl;
    }
}

Answer: 1


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

int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
	// your code goes here
    int t;
    cin>>t;

    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;

        //int a[n];
        map<int, int> mp;

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

        totaluniq=mp.size();

        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }

        sort(pq.begin(), pq.end());
        int ctr=0;

        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;

            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }

        cout<<totaluniq<<endl;
        }
    }
}

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

int main() {
	// your code goes here
    int t;
    cin>>t;

    while(t--)
    {
        int i,n,k,totaluniq;
        cin>>n>>k;

        //int a[n];
        unordered_map<int, int> mp;

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

        totaluniq=mp.size();

        if(k==0)
        {
            cout<<totaluniq<<endl;
        }
        else if(k>=n-1)
        {
            cout<<1<<endl;
        }
        else
        {
        vector<int> pq;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            pq.push_back(it->second);
        }

        sort(pq.begin(), pq.end());
        int ctr=0;

        for(auto it=pq.begin(); it!=pq.end()&&ctr<k&&totaluniq>1; it++)
        {
            int freq=*it;

            if(freq+ctr<=k)
            {ctr+=freq;
            totaluniq--;
            }
            else
            {
                break;
            }
        }

        cout<<totaluniq<<endl;
        }
    }
}

Answer: 1


#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ULL;
const int N=4e5 + 5;
using namespace std;
vector<int>vv;
void solve(){
  int a,b,sum=0;
  cin>>a>>b;
  set<int>se;
  map<int,int>m;
  for(int i=0;i<a;i++){
    int c;
    cin>>c;
    se.insert(c);
    m[c]++;
  }
  vector<int>v;
  for(auto i:se){
    v.push_back(m[i]);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<v.size();i++){
    if(v[i]<=b){
      b-=v[i];
      continue;
    }
    sum++;

  }
  if(sum==0)sum++;
  vv.push_back(sum);
}
int main(){
  int t;
  cin>>t;
  while(t--)solve();
  for(auto i:vv)cout<<i<<'\n';
}

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ULL;
const int N=4e5 + 5;
using namespace std;
void solve(){
  int a,b,sum=0;
  cin>>a>>b;
  set<int>se;
  map<int,int>m;
  for(int i=0;i<a;i++){
    int c;
    cin>>c;
    se.insert(c);
    m[c]++;
  }
  vector<int>v;
  for(auto i:se){
    v.push_back(m[i]);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<v.size();i++){
    if(v[i]<=b){
      b-=v[i];
      continue;
    }
    sum++;

  }
  if(sum==0)sum++;
  cout<<sum<<'\n';
  for(auto i:v)cout<<i<<" ";
}
int main(){
  int t;
  cin>>t;
  while(t--)solve();
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
int arr[100002];
void solve(){
    int n,k;
    cin>>n>>k;
    unordered_map<int,int>mp;
    int x;
    for(int i=0;i<n;i++){
        cin>>x;
        mp[x]++;
    }
    int size=mp.size();
    priority_queue<int,vector<int>,greater<int>>pq;
    int i=0;
    for(auto it:mp){
        arr[i++]=it.second;
    }
    sort(arr,arr+i);
    for(int j=0;j<i;j++){
        if(k>=arr[j]){
            k-=arr[j];
            size--;
        }
        else break;
    }
    if(size<=0)size=1;
    cout<<size<<endl;
}
int main() {
	int t;
	cin>>t;
	while(t--){
	    solve();
	}

}

#include <bits/stdc++.h>
using namespace std;
int arr[100002];
map<int,int>mp;
void solve(){
    int n,k;
    cin>>n>>k;
    mp.clear();
    int x;
    for(int i=0;i<n;i++){
        cin>>x;
        mp[x]++;
    }

    int i=0;
    for(auto it:mp){
        arr[i++]=it.second;
    }
    int size=i;
    sort(arr,arr+i);
    for(int j=0;j<i;j++){
        if(k>=arr[j]){
            k-=arr[j];
            size--;
        }
        else break;
    }
    if(size<=0)size=1;
    cout<<size<<endl;
}
int main() {
	int t;
	cin>>t;
	while(t--){
	    solve();
	}

}

Answer: 2


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

#define int unsigned long long
#define dub long double
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef unordered_map<int,int> umap;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(a) a.begin(),a.end()
#define endl '\n'
#define INF 2147483647
//#define INF 9223372036854775807
#define null '\0'
const int N = 1e5 + 10, Mod = 1e9 + 7;
int n,m;
int fact[N];
void solve(){
    string s,t;
    cin >> s >> t;
    n = s.size();
    m = t.size();
    vector<vint> dp(n+1,vint(m+1));
    vector<vint> pi(n+1,vint(m+1));
    rep(i,0,n+1) {
        rep(j,0,m+1) {
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else {
                if(s[i-1] == t[j-1])
                    dp[i][j] = dp[i-1][j-1] + 1;
                else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
            }
        }
    }
//    cout << "check\n";
    int res = n + m - dp[n][m];
    int ans = 1;
    rep(i,0,n+1) {
        rep(j,0,m+1) {
            if(i == 0 || j == 0) pi[i][j] = min(i,j) + 1;
            else if(dp[i][j] > dp[i-1][j-1]) {
                pi[i][j] = pi[i-1][j-1];
            }
            else
                pi[i][j] = pi[i-1][j] + pi[i][j-1];
        }
    }
    cout << pi[n][m] << endl;

}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_n = 1;
    cin>>test_n;
    for(int t_c = 1;t_c <= test_n;t_c ++){
        cout << "Case "<<t_c<<": ";
        solve();
    }
    return 0;
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        map<int,int> freq;
        for(int num: arr){
            freq[num]++;
        }
        vector<int> counts;
        for(auto &entry: freq){
            counts.push_back(entry.second);
        }
        sort(counts.begin(),counts.end());
        long long sum=0;
        int i=0;
        for(int count: counts){
            if(sum+count<=k){
                i++;
                sum+=count;
            }
            else{
                break;
            }
        }
        int ans=counts.size()-i;
        if(ans>0){
            cout<<ans<<endl;
        }
        else{
            cout<<1<<endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        int n, k;
        cin >> n >> k;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }

        unordered_map<int, int> freq;
        for(int num : arr){
            freq[num]++;
        }

        priority_queue<int, vector<int>, greater<int>> minHeap;
        for(auto &entry : freq){
            minHeap.push(entry.second);
        }

        int sum=0,removed=0;
        while(!minHeap.empty() && sum + minHeap.top()<=k){
            sum+=minHeap.top();
            minHeap.pop();
            removed++;
        }
        int ans = minHeap.size();
        cout << (ans > 0 ? ans : 1) << endl;
    }
    return 0;
}

Answer: 1


/**

                            * بسم الله الرحمن الرحيم *

    ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿

**/
#include <bits/stdc++.h>
#define ll long long
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vllll vector<vll>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define pd push_back
using namespace std;

void solving(){
    ll n,k; cin>>n>>k;
    ll a[n];
    unordered_map<ll,ll> mp;
    fi(0,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vll counts;
    for(auto e:mp ){
        counts.push_back(e.second);
    }
    sort(all(counts));
    ll e1=0;
    ll e2=counts.size()-1;
    ll res=counts.size();
    while(e1<e2){
        if(counts[e1]<=k){
            k-=counts[e1];
            res--;
            e1++;
        }else break;
    }
    cout<<res<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    while(n--) solving();
}

/**

                            * بسم الله الرحمن الرحيم *

    ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿

**/
#include <bits/stdc++.h>
#define ll long long
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vllll vector<vll>
#define vpll vector<pair<ll,ll>>
#define vb vector<bool>
#define pd push_back
using namespace std;

void solving(){
    ll n,k; cin>>n>>k;
    ll a[n];
    map<ll,ll> mp;
    fi(0,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vll counts;
    for(auto e:mp ){
        counts.push_back(e.second);
    }
    sort(all(counts));
    ll e1=0;
    ll e2=counts.size()-1;
    ll res=counts.size();
    while(e1<e2){
        if(counts[e1]<=k){
            k-=counts[e1];
            res--;
            e1++;
        }else break;
    }
    cout<<res<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    while(n--) solving();
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int> a(n);
        set<int> s;
        unordered_map<int,int> m;
        vector<int> freq;
        for(int i=0;i<n;i++){
            cin>>a[i];
            m[a[i]]++;

            s.insert(a[i]);
        }
        for (unordered_map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
            freq.push_back(it->second);
        }
        sort(freq.begin(),freq.end());

        int ans=s.size();
        for(int i=0;i<freq.size();i++){
            if(k>=freq[i]){
                k=k-freq[i];
                ans--;
            }
            else {
                break;
            }
        }
        if(ans==0) cout<<"1"<<endl;
       else  cout<<ans<<endl;

    }
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int> a(n);
        //set<int> s;

        map<int,int> m;
        vector<int> freq;
        for(int i=0;i<n;i++){
            cin>>a[i];
            m[a[i]]++;

            //s.insert(a[i]);
        }
        for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
            freq.push_back(it->second);
        }
        sort(freq.begin(),freq.end());

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

    }
}

Answer: 2


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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int temp = k;
        vector<int>v(n);
        map<int,int>m;
        vector<int>v2(n);
        for(int i=0;i<v.size();i++){
            cin>>v[i];
            m[v[i]]++;
        }
        int max = m[v[0]];
        // int idx = v[0];
        for(auto i:m){
            if(i.second>max){
                max = i.second;
                // idx = i.first;
            }
            // max = i.second;
        }
        // m[idx] = 0;
        // if (temp == 0){

        //     cout<<m.size()<<endl;
        //     continue;
        // }
        for(auto i:m){
            v2.push_back(i.second);
        }
        sort(v2.begin(),v2.end());

        for(int i=0;i<v2.size();i++){
            if(k>=v2[i]){
                k = k - v2[i];
                v2[i] = 0;
            }
        }
        // k = temp;
        int count = 0;
        for(int i=0;i<v2.size();i++){
            if(v2[i] != 0) count++;
        }

        // for(int i=0;i<v2.size();i++){
        //     cout<<v2[i]<<" ";
        // }cout<<endl;
        if(count == 0){
            cout<<1<<endl;
        }

        else if(m.size() == temp && n == temp ){
            cout<<1<<endl;
        }
        else{
            cout<<(count)<<endl;
        }

}
}

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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int>v(n);
        map<int,int>m;
        vector<int>v2(n);
        for(int i=0;i<v.size();i++){
            cin>>v[i];
            m[v[i]]++;
        }
        int max = m[v[0]];
        int idx;
        for(auto i:m){
            if(i.second>max){
                max = i.second;
                idx = i.first;
            }
            // max = i.second;
        }
        m[idx] = 0;
        for(auto i:m){
            v2.push_back(i.second);
        }
        sort(v2.begin(),v2.end());

        for(int i=0;i<v2.size();i++){
            if(k>0){
                k = k - v2[i];
                v2[i] = 0;
            }
        }

        int count = 0;
        for(int i=0;i<v2.size();i++){
            if(v2[i] != 0) count++;
        }
        if(n==1){
            cout<<1<<endl;
        }
        else{
            cout<<count+1<<endl;
        }
        // cout<<(count+1)<<endl;

}
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> nums(n,0);
    for(int i=0;i<n;i++){
        cin>>nums[i];
    }
    sort(nums.begin(),nums.end());
    vector<int>sum={1};
    for(int i=1;i<n;i++){
        if(nums[i]==nums[i-1]){
            sum.back()++;
        }
        else{
            sum.push_back(1);
        }
    }
    sort(sum.begin(),sum.end());
    for(int i=0;i<sum.size();i++){
        if(k<sum[i]){
            cout<<sum.size()-i<<"\n";
            return;
        }
        k-=sum[i];
    }
    cout<<1<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
auto compare = [](const pair<int, int>& a, const pair<int, int>& b) {
    return a.second < b.second;
    };
void solve(){
    int n,k;
    cin>>n>>k;
    unordered_map<int,int>umap;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        umap[num]++;
    }
    vector<pair<int,int>>pq;
    for(auto const&pairs:umap){
        pq.push_back(make_pair(pairs.first,pairs.second));
    }
    sort(pq.begin(),pq.end(),compare);
    int i=0;
    while(k>0&&pq.size()>0){
        auto top = pq[i];
        if(k>=top.second){
            k-=top.second;
            pq[i++].second=0;
        }
        else{
            break;
        }
    }
    int account=0;
    for(int j=0;j<pq.size();j++){
        if(pq[j].second!=0){
            account++;
        }
    }
    if(account!=0)
        cout<<account<<"\n";
    else
        cout<<1<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Answer: 1


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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);

  int t;
  cin>>t;
  while(t--){
    int n;
    int k;
    cin>>n>>k;
    vector<long long>a(n);
    int i=0;
    map<long long,int>mp;
    for(i=0;i<n;i++){
      cin>>a[i];
      mp[a[i]]++;
    }
    if(n==k)
    cout<<"1"<<endl;
    else{
   vector<int>f;
   int c=0;
   f.reserve(n);
   for(auto p:mp){
     f.push_back(p.second);
     c++;
   }
   sort(f.begin(),f.end());
   int s=0;
   int co=0;
   for(i=0;i<c;i++){
    if((s+f[i])<=k){
      s=s+f[i];
      co++;
    }
     else if((s+f[i])>k){
       break;
     }
   }
   cout<<(c-co)<<endl;
    }
  }
  return 0;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);

  int t;
  cin>>t;
  while(t--){
    int n;
    int k;
    cin>>n>>k;
    vector<long long>a(n);
    int i=0;
    unordered_map<long long,int>mp;
    for(i=0;i<n;i++){
      cin>>a[i];
      mp[a[i]]++;
    }
    int c=0;
    for(auto p:mp){
      c++;
    }
    if(c<k)
    cout<<"0"<<endl;
    else
    cout<<(c-k)<<endl;
  }
  return 0;
}

Answer: 1


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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    long long t;
    cin >> t;

    while (t--)
    {
        long long n, k;
        cin >> n >> k;
        long long arr[n];

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

        map<long long, long long> freq;
        for (long long num : arr) {
            freq[num]++;
        }

        vector<pair<long,long>>p;
        for(auto it : freq)
        {
               p.push_back({it.second,it.first});
        }
        sort(p.begin(),p.end());

        long long count = p.size();
        for(auto it:p)
        {
               if(k>=it.first)
               {
                     k-=it.first;
                     count--;
               }
               else
               {
                     break;
               }
        }
        if(count<=0)
        cout<<1<<endl;
        else
        cout << count << endl;

    }

    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    long long t;
    cin >> t;

    while (t--)
    {
        long long n, k;
        cin >> n >> k;
        long long arr[n];

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

        unordered_map<long long, long long> freq;
        for (long long num : arr) {
            freq[num]++;
        }

        priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;
        for (const auto& entry : freq) {
            pq.push({entry.second, entry.first});
        }

        long long count = 0;
        while (k > 0 && !pq.empty()) {
            pair<long long, long long> top = pq.top();
            pq.pop();

            long long temp = min(top.first, k);
            k -= temp;

            if (temp < top.first) {
                pq.push({top.first - temp, top.second});
                break;
            }
        }
        if(pq.empty())
        count = 1;

        while (!pq.empty()) {
            pq.pop();
            count++;
        }

        cout << count << endl;
    }

    return 0;
}

Answer: 1


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

template <typename K, typename V>
std::vector<std::pair<K, V>> sortMapByValue(const std::map<K, V> &mp) {
    std::vector<std::pair<K, V>> vec(mp.begin(), mp.end());

    std::sort(vec.begin(), vec.end(), [](const auto &a, const auto &b) {
        return a.second < b.second; // Sort in ascending order by value
    });

    return vec;
}

int main()
{
    int t;
    cin >> t;
    while(t--){
        int n, k;
        cin >> n >> k;
        vector<int> v;
        for(int i = 0; i < n; i++){
            int x;
            cin >> x;
            v.push_back(x);
        }

    std::map<int, int> values;

    for(int i=0; i<n; i++){
        values[v[i]]++;
    }
    int res=0;
   auto v2=sortMapByValue(values);
    for(int i=0; i<v2.size(); i++){
        k=k-v2[i].second;
        if(k<=0){

            break;
        }
        res++;

    }
    cout<<res+1<<endl;
    }
}

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

template <typename K, typename V>
std::vector<std::pair<K, V>> sortMapByValue(const std::map<K, V> &mp) {
    std::vector<std::pair<K, V>> vec(mp.begin(), mp.end());

    std::sort(vec.begin(), vec.end(), [](const auto &a, const auto &b) {
        return a.second < b.second; // Sort in ascending order by value
    });

    return vec;
}

int main()
{
    int t;
    cin >> t;
    while(t--){
        int n, k;
        cin >> n >> k;
        vector<int> v;
        for(int i = 0; i < n; i++){
            int x;
            cin >> x;
            v.push_back(x);
        }

    std::map<int, int> values;

    for(int i=0; i<n; i++){
        values[v[i]]++;
    }
    int res=0;
   auto v2=sortMapByValue(values);
    for(int i=0; i<v2.size(); i++){

        if(k>=v2[i].second){
            k-=v2[i].second;
            v2[i].second=0;

        }

    }
    for(int i=0; i<v2.size(); i++){
        if(v2[i].second>0){
            res++;
        }
    }
    if(res==0){
        res=1;
    }

    cout<<res<<endl;
    }
}

Answer: 2


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    unordered_map<int, int> mp;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      mp[x]++;
    }
    vector<int> a;
    for(auto e : mp) { a.push_back(e.second); }
    sort(a.begin(), a.end());
    int ans = a.size();
    a.pop_back();
    for (auto e : a) {
      if (k >= e) {
        k -= e;
        ans --;
      } else break;
    }
    cout << ans << endl;
  }
  return 0;
}

#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    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> b;
    int cnt = 1;
    for (int i = 1; i < n; i++) {
      if (a[i] == a[i - 1]) { cnt ++; }
      else {
        b.push_back(cnt);
        cnt = 1;
      }
    }
    b.push_back(cnt);
    sort(b.begin(), b.end());

    int ans = b.size();
    b.pop_back();
    for (auto e : b) {
      if (k >= e) {
        k -= e;
        ans --;
      } else break;
    }
    cout << ans << endl;
  }
  return 0;
}

Answer: 2


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

int return1(long long int a , long long int b){
    if((a<0 && b<0 )|| (a>0 && b>0)){
        return 1;
    }
    if(a==0 && b==0){
        return 0;
    }
    return -1;
}

int main(){

    unsigned int testcase;
    std::cin>>testcase;

    while(testcase--){
        int a , b;
        std::unordered_map<long long int , long long int>arr;
        std::cin>>a>>b;
        for(int i=0;i<a;i++){
            long long int y;
            std::cin>>y;
            arr[y]++;
        }

        std::vector<int>arr2;
        for(auto n:arr){
            arr2.push_back(n.second);
        }

        std::sort(arr2.begin() , arr2.end());
        int counter=1;
        int i;
        for(i=0;i<arr2.size()-1; i++){
            if(b<arr2[i]){
                break;
            }
            b-=arr2[i];
        }
        std::cout<<counter+arr2.size()-1-i<<"\n";
}    return 0;
}

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    std::sort(a.begin(), a.end());
    std::vector<int> cnt = {1};
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            cnt.back()++;
        } else {
            cnt.emplace_back(1);
        }
    }
    std::sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    for (int i = 0; i < m - 1; i++) {
        if (cnt[i] > k) {
            std::cout << m - i << "\n";
            return;
        }
        k -= cnt[i];
    }
    std::cout << 1 << "\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    std::cin >> t;

    while (t--) {
        solve();
    }
}

Answer: 2


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

#define md : 1000000007;

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

    vector<int> vec(n);

    unordered_map<int,int> mp;
    vector<int>count = {1};

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

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

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

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

    int res = count.size()-i != 0 ? count.size()-i : 1;

    cout << res <<  endl;
    // priority_queue<pair<int,int>, vector<pair<int,int>>, greater<> > st;

    // for(auto x: mp){
    //     st.push({x.second, x.first});
    // }

    // int count = 0;

    // while(!st.empty() && k){
    //     int temp = (st.top()).first;
    //     if(temp > k) k = 0;
    //     else{
    //         k-=temp;
    //         st.pop();
    //     }
    // }

    // st.size() > 0 ? cout <<  st.size() : cout << 1 ;
    // cout << endl;

}

int main(){

    int t;
    cin>>t;

    while(t--)
        solve();

    return 0;
}

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

#define md : 1000000007;

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

    vector<int> vec(n);
    vector<int>count = {1};

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

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

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

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

    cout << m-i <<  endl;
    // priority_queue<pair<int,int>, vector<pair<int,int>>, greater<> > st;

    // for(auto x: mp){
    //     st.push({x.second, x.first});
    // }

    // int count = 0;

    // while(!st.empty() && k){
    //     int temp = (st.top()).first;
    //     if(temp > k) k = 0;
    //     else{
    //         k-=temp;
    //         st.pop();
    //     }
    // }

    // st.size() > 0 ? cout <<  st.size() : cout << 1 ;
    // cout << endl;

}

int main(){

    int t;
    cin>>t;

    while(t--)
        solve();

    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
	int t;
	cin>>t;
	while(t--){
		long long n,m;
		cin>>n>>m;
		mp.clear();
		for(int i=1;i<=n;i++){
			int a;
			cin>>a;
			mp[a]++;
		}
		multiset<int>st;
		for(auto b:mp)
			st.insert(b.second);
		int ans=st.size();
		for(int a:st){
			if(m>=a)ans--,m-=a;
		}cout<<max(1,ans)<<'\n';
	}
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int T; // Number of test cases
    cin >> T;

    while (T--) {
        int n, m;
        cin >> n >> m;

        vector<long long> a(n); // Input array
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        // Sort the array to group identical values together
        sort(a.begin(), a.end());

        // Calculate frequencies of each distinct element
        vector<long long> freq;
        long long count = 1; // Frequency counter
        for (int i = 1; i < n; i++) {
            if (a[i] == a[i - 1]) {
                count++; // Increment frequency if the same value continues
            } else {
                freq.push_back(count); // Store frequency
                count = 1;             // Reset frequency counter
            }
        }
        freq.push_back(count); // Add the last frequency

        // Sort the frequencies to handle smallest groups first
        sort(freq.begin(), freq.end());

        // Minimize the number of distinct groups
        int distinct_groups = freq.size(); // Start with all groups
        for (int i = 0; i < freq.size(); i++) {
            if (m >= freq[i]) {
                m -= freq[i];     // Use changes to eliminate this group
                distinct_groups--; // Reduce the count of distinct groups
            } else {
                break; // No more changes can be made
            }
        }

        // Output the result for this test case
        cout << distinct_groups << endl;
    }

    return 0;
}

Answer: 1


#include <stdio.h>
#include <stdlib.h>

int sort (const void* a, const void* b) {
    return (*(int*)a - *(int*)b);
}

int main() {
    int x;
    scanf("%d", &x);

    while (x--) {
        int n, k;
        scanf("%d %d", &n, &k);

        int* a = (int*)malloc(n * sizeof(int));
        int max = 0;
        for (int i=0; i<n; i++) {
            scanf(" %d", &a[i]);

            if (a[i] > max) {
                max = a[i];
            }
        }

        int* count = (int*)calloc(max + 1, sizeof(int));
        for (int i=0; i<n; i++) {
            count[a[i]]++;
        }

        int b = 0;
        int* c = (int*)malloc(n * sizeof(int));
        for (int i=1; i<=max; i++) {
            if (count[i] > 0) {
                c[b++] = count[i];
            }
        }

        qsort(c, b, sizeof(int), sort);

        int ans = b;
        for (int i=0; i<b; i++) {
            if (c[i] <= k) {
                k = k - c[i];
                ans--;
            }
            else {
                break;
            }
        }

        if (ans == 0) {
            ans = 1;
        }
        printf("%d \n", ans);
    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int sort (const void* a, const void* b) {
    return (*(int*)a - *(int*)b);
}

int main() {
    int x;
    scanf("%d", &x);

    while (x--) {
        int n, k;
        scanf("%d %d", &n, &k);

        int* a = (int*)malloc(n * sizeof(int));
        int max = 0;
        for (int i=0; i<n; i++) {
            scanf(" %d", &a[i]);
        }

        qsort(a, n, sizeof(int), sort);

        int* count = (int*)malloc(n * sizeof(int));
        int c = 1;
        int m = 0;
        for (int i=0; i<n-1; i++) {
            if (a[i] == a[i+1]) {
                c++;
            }
            else {
                count[m++] = c;
                c = 1;
            }
        }

        count[m++] = c;

        qsort(count, m, sizeof(int), sort);

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

        if (ans == 0) {
            ans = 1;
        }
        printf("%d \n", ans);

        free(a);
        free(count);
    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t ;
    cin >> t;
    while (t--)
    {
        int  n;
        int k;
        cin >> n >> k;
        int arr[n];
        for ( int i = 0 ; i < n ; i++){
            cin >> arr[i];
        }
        sort(arr, arr + n);
      	int cnt = 1;
      	vector<int> frequency;
        for( int j = 1 ; j < n ; j++){
          	if(arr[j]!=arr[j-1]){
              	frequency.push_back(cnt);
                cnt=1;
            }
        	cnt++;
    	}
        	frequency.push_back(cnt);
      	sort(frequency.begin(), frequency.end());
      	int ans = frequency.size();
      	for( int i = 0 ; i < frequency.size() ; i++){
          if( k >= frequency[i] ) {
            k -= frequency[i];
            ans--;
          }else{
            break;
          }
        }
      cout << max(ans, 1) << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t ;
    cin >> t;
    while (t--)
    {
        int  n;
        int k;
        cin >> n >> k;
        int arr[n];
        for ( int i = 0 ; i < n ; i++){
            cin >> arr[i];
        }
        sort(arr, arr + n);
      	int cnt = 1;
      	vector<int> frequency;
        for( int j = 1 ; j < n ; j++){
          	if(arr[j]!=arr[j-1]){
              	frequency.push_back(cnt);
                cnt=0;
            }
        	cnt++;
    	}
        	frequency.push_back(cnt);
      	sort(frequency.begin(), frequency.end());
      	int ans = frequency.size();
      	for( int i = 0 ; i < frequency.size() ; i++){
          if( k >= frequency[i] ) {
            k -= frequency[i];
            ans--;
          }else{
            break;
          }
        }
      cout << max(ans, 1) << endl;
    }

    return 0;
}

Answer: 2


for q in range(int(input())):
    n,k=list(map(int,input().split(' ')))
    a=list(map(int,input().split(' ')))
    b=set(a)
    d={}
    for i in b:
        d[i]=0
    for i in a:
        d[i]+=1
    l=[]
    for i in d:
        l.append(d[i])
    pre=0
    ans=len(l)
    l.sort()
    for i in range(len(l)):
        if(pre+l[i]<=k):
            pre+=l[i]
            ans-=1
    print(max(ans,1))

for q in range(int(input())):
    n,k=list(map(int,input().split(' ')))
    a=list(map(int,input().split(' ')))
    d={}
    for i in range(n):
        if(a[i] not in d):
            d[a[i]]=1
        else:
            d[a[i]]+=1
    l=[]
    for i in d:
        l.append(d[i])
    pre=0
    ans=len(l)
    l.sort()
    for i in range(len(l)):
        if(pre+l[i]<=k):
            pre+=l[i]
            ans-=1
    print(max(ans,1))

Answer: 1


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

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

    int n;
    int k;
    cin >> n >> k;

    int a;
    map< int , int > mpp;
    for(int i=0;i<n;i++){
      cin >> a;
      mpp[a]++;

    }

    vector<int>ans;

    for(auto it:mpp){
      ans.push_back(it.second);
    }

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

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

    cout << mini << endl;
  }
}

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

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

    int n;
    int k;
    cin >> n >> k;

    int a;
    map< int , int > mpp;
    for(int i=0;i<n;i++){
      cin >> a;
      mpp[a]++;

    }

    vector<int>ans;

    for(auto it:mpp){
      ans.push_back(it.second);
    }

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

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

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

Answer: 2


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        //set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            //s.insert(a[i]);
            freq[a[i]]++;
        }
        if(k>=n-1) {cout << "1\n";}
        else {
            vector <pair<long int,int>> f;
            for (const auto& elem : freq) {
                f.push_back(elem);
            }
            sort(f.begin(), f.end(),
            [](const pair<long int, int>& a, const pair<long int, int>& b) {
                return a.second > b.second;
            });
            for(int i=0;i<k;i++) {
                int last=f.size();
                f[last-1].second--;
                if(f[last-1].second==0) {f.pop_back();}
            }
            cout << f.size() << "\n";
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            s.insert(a[i]);
            freq[a[i]]++;
        }
        vector <pair<long int,int>> f;
        for (const auto& elem : freq) {
            f.push_back(elem);
        }
        sort(f.begin(), f.end(),
        [](const pair<long int, int>& a, const pair<long int, int>& b) {
            return a.second < b.second;  // Compare the second element of each pair
        });
        int index=0;
        for(int i=0;i<k;i++) {
            f[index].second--;
            if(f[index].second==0) {
                s.erase(f[index].first);
                index++;
            }
            if(index==n-1) {break;}
        }
        cout << s.size() << "\n";
    }
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"

void solve(){

    int n,k;
    cin>>n>>k;
    map<int,int>m;
    vector<int>v;

    for (int i=1; i<=n; ++i) {
        int x;
        cin>>x;
        m[x]++;
    }

    for(auto it:m)
        v.push_back(it.second);
    sort(v.begin(),v.end());
    int s=(int)v.size();

    for (int i=0; i<v.size(); ++i) {
        if(k>=v[i]){
            k-=v[i];
            s--;
        }
        else break;
    }
    s?cout<<s<<endl:cout<<1<<endl;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"

void solve(){

    int n,k;
    cin>>n>>k;
    map<int,int>m;
    vector<int>v;

    for (int i=1; i<=n; ++i) {
        int x;
        cin>>x;
        m[x]++;
    }

    for(auto it:m)
        v.push_back(it.second);

    int s=(int)v.size();

    for (int i=0; i<v.size(); ++i) {
        if(k>=v[i]){
            k-=v[i];
            s--;
        }
        else break;
    }
    s?cout<<s<<endl:cout<<1<<endl;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

Answer: 1


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

int main()
{
    int t;
    cin>>t;

    while(t--){
        int n,k;
        cin>>n>>k;

        // vector<int> v(n);

        unordered_map<int,int> mp;
        int x;
        for(int i=0;i<n;i++){
            cin>>x;
            mp[x]++;
        }

        vector<int> freq;

        for(auto p:mp){
            freq.push_back(p.second);
        }

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

        int ans = 1;

        int i=0;
        for(int i=0;i<freq.size()-1;i++){
            if(k>=freq[i]){
                k-=freq[i];
            }else{
                ans++;
            }
        }

        cout<<ans<<endl;

    }
}

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

int main()
{
    int t;
    cin>>t;

    while(t--){
        int n,k;
        cin>>n>>k;

        // vector<int> v(n);

        map<int,int> mp;
        int x;
        for(int i=0;i<n;i++){
            cin>>x;
            mp[x]++;
        }

        vector<int> freq;

        for(auto p:mp){
            freq.push_back(p.second);
        }

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

        int ans = 1;

        int i=0;
        for(int i=0;i<freq.size()-1;i++){
            if(k>=freq[i]){
                k-=freq[i];
            }else{
                ans++;
            }
        }

        cout<<ans<<endl;

    }
}

Answer: 2


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

int main() {
    int T; // Number of test cases
    cin >> T;

    while (T--) {
        long long n, m;
        cin >> n >> m;

        vector<long long> a(n); // Array to store input numbers
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        // Sort the array to group identical elements
        sort(a.begin(), a.end());

        vector<long long> freq; // Frequency array for unique elements
        long long count = 1; // Initialize frequency counter

        // Calculate frequencies
        for (int i = 1; i < n; i++) {
            if (a[i] != a[i - 1]) {
                freq.push_back(count); // Store frequency
                count = 1;             // Reset counter
            } else {
                count++;
            }
        }
        freq.push_back(count); // Add the last frequency

        // Sort the frequency array
        sort(freq.begin(), freq.end());

        // Start with all distinct groups
        long long distinct_groups = freq.size();

        // Use available changes to reduce distinct groups
        for (auto f : freq) {
            if (m >= f) {
                m -= f;               // Use changes for this group
                distinct_groups--;    // Reduce group count
            } else {
                break; // No more changes can be used
            }
        }

        // Output the result
        cout << distinct_groups << '\n';
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
	int t;
	cin>>t;
	while(t--){
		long long n,m;
		cin>>n>>m;
		mp.clear();
		for(int i=1;i<=n;i++){
			int a;
			cin>>a;
			mp[a]++;
		}
		multiset<int>st;
		for(auto b:mp)
			st.insert(b.second);
		int ans=st.size();
		for(int a:st){
			if(m>=a)ans--,m-=a;
		}cout<<max(1,ans)<<'\n';
	}
}

Answer: 2


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

void solver() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int input; cin >> input;
    while(input--) {
        int n, k; cin >> n >> k;
        map<int, int> map;
        int num;
        for(int i = 0; i < n; i++) {
            cin >> num;
            map[num]++;
        }

        vector<int> vec;
        for(auto ele: map) vec.push_back(ele.second);
        sort(vec.begin(), vec.end());

        int passes = vec.size();

        for(int i = 0; k > 0 && i < vec.size() - 1; i++) {
            int temp = min(vec[i], k);
            vec[i] -= temp;
            k -= temp;
            if(vec[i] == 0) passes--;
        }

        cout << passes << "\n";
    }
}

int main(){

    solver();

}

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

void solver() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int input; cin >> input;
    while(input--) {
        int n, k; cin >> n >> k;
        unordered_map<int, int> map;
        int num;
        for(int i = 0; i < n; i++) {
            cin >> num;
            map[num]++;
        }

        vector<int> vec;
        for(auto ele: map) vec.push_back(ele.second);
        sort(vec.begin(), vec.end());

        for(int i = 0; k > 0 && i < vec.size() - 1; i++) {
            int temp = min(vec[i], k);
            vec[i] -= temp;
            k -= temp;
            vec[vec.size() - 1] += temp;
        }

        int passes = 0;
        for(int i = 0; i < vec.size() - 1; i++) passes += (vec[i] > 0);
        cout << passes + 1 << "\n";
    }
}

int main(){

    solver();

}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t ;
    cin >> t;
    while (t--)
    {
        int  n;
        int k;
        cin >> n >> k;
        int arr[n];
        for ( int i = 0 ; i < n ; i++){
            cin >> arr[i];
        }
        sort(arr, arr + n);
      	int cnt = 1;
      	vector<int> frequency;
        for( int j = 1 ; j < n ; j++){
          	if(arr[j]!=arr[j-1]){
              	frequency.push_back(cnt);
                cnt=1;
            }
        	cnt++;
    	}
      	sort(frequency.begin(), frequency.end());
      	int ans = frequency.size();
      	for( int i = 0 ; i*1ULL < frequency.size() ; i++){
          if( k >= frequency[i] ) {
            k -= frequency[i];
            ans--;
          }
        }
      cout << ans << endl;
    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define ll long long

// sorting 2D MATRIX.....
// bool cmp(vector<ll> &a, vector<ll> &b)
// {
//     ll ans1=accumulate(a.begin(),a.end(),0ll);
//     ll ans2=accumulate(b.begin(),b.end(),0ll);
//     if(ans1==ans2)
//     {
//         for (int i = 0; i < a.size(); ++i)
//         {
//             if(a[i]!=b[i])
//             {
//                 return a[i]>b[i];
//             }
//         }
//     }
//     return ans1>ans2;
// }

// void solve() {
//     int t;
//     cin >> t;
//     while (t--) {
//         string s;
//         cin >> s;
//         int n = s.length();

//         // Option 1: "((((...))))"
//         string t1 = string(n, '(') + string(n, ')');

//         // Option 2: "()()()()"
//         string t2 = "";
//         for (int i = 0; i < n; i++) t2 += "()";

//         // If s is not found as a substring, print it
//         if (t1.find(s) == string::npos) {
//             cout << "YES\n" << t1 << "\n";
//         } else if (t2.find(s) == string::npos) {
//             cout << "YES\n" << t2 << "\n";
//         } else {
//             cout << "NO\n";
//         }
//     }
// }

void solve()
{
    int t; cin>>t;
    while(t--)
    {
        int n,k; cin>>n>>k;
        vector<ll>v(n);
        map<ll,ll> m;
        for (int i = 0; i < n; ++i)
        {
            cin>>v[i];
            m[v[i]]++;
        }
        vector<ll>freq;
        for(auto it: m)
        {
            freq.push_back(it.second);
        }
        sort(freq.begin(),freq.end());
        ll idx=0;
        for (int i = 0; i < freq.size(); ++i)
        {
            if(freq[i]<=k)
            {
                k-=freq[i];
                idx=i+1;
            }
            else break;
        }
        ll ans=(freq.size()-idx);
        cout<<max(1ll,ans)<<endl;
    }
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define ll long long

// sorting 2D MATRIX.....
// bool cmp(vector<ll> &a, vector<ll> &b)
// {
//     ll ans1=accumulate(a.begin(),a.end(),0ll);
//     ll ans2=accumulate(b.begin(),b.end(),0ll);
//     if(ans1==ans2)
//     {
//         for (int i = 0; i < a.size(); ++i)
//         {
//             if(a[i]!=b[i])
//             {
//                 return a[i]>b[i];
//             }
//         }
//     }
//     return ans1>ans2;
// }

// void solve() {
//     int t;
//     cin >> t;
//     while (t--) {
//         string s;
//         cin >> s;
//         int n = s.length();

//         // Option 1: "((((...))))"
//         string t1 = string(n, '(') + string(n, ')');

//         // Option 2: "()()()()"
//         string t2 = "";
//         for (int i = 0; i < n; i++) t2 += "()";

//         // If s is not found as a substring, print it
//         if (t1.find(s) == string::npos) {
//             cout << "YES\n" << t1 << "\n";
//         } else if (t2.find(s) == string::npos) {
//             cout << "YES\n" << t2 << "\n";
//         } else {
//             cout << "NO\n";
//         }
//     }
// }

void solve()
{
    int t; cin>>t;
    while(t--)
    {
        int n,k; cin>>n>>k;
        vector<ll>v(n);
        map<ll,ll> m;
        for (int i = 0; i < n; ++i)
        {
            cin>>v[i];
            m[v[i]]++;
        }
        ll cheak=INT_MIN;
        for(auto it: m)
        {
            cheak=max(cheak,(it).second);
        }
        if(n==1) cout<<1<<endl;
        else if(k==0) cout<<n-cheak<<endl;
        else cout<<(n-cheak+k-1)/k<<endl;
    }
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

Answer: 1


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

int main(void)
{
    int T;
    cin >> T;
    while(T--)
    {
        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> cnt={1};
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i-1])
            {
                cnt.back()++;
            }else
            {
                cnt.emplace_back(1);
            }
        }
        sort(cnt.begin(),cnt.end());
        int m=cnt.size();
        for(int i=0;i<m;i++)
        {
            if(k<cnt[i])
            {
                cout << m-i << endl;
                continue;
            }
            k-=cnt[i];
        }
        cout << 1 << endl;
    }
}

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

int main(void)
{
    int T;
    cin >> T;
    while(T--)
    {
        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> cnt={1};
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i-1])
            {
                cnt.back()++;
            }else
            {
                cnt.emplace_back(1);
            }
        }
        sort(cnt.begin(),cnt.end());
        int m=cnt.size();
        for(int i=0;i<m;i++)
        {
            if(k<cnt[i])
            {
                cout << m-i << endl;
                k=-1;
                break;
            }
            k-=cnt[i];
        }
        if(k>=0) cout << 1 << endl;
    }
}

Answer: 2


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; // number of test cases
    cin >> t;
    while (t--) {
        int n, k;
        cin>>n>>k;
        vector<int> a(n);
        map<int , int> n2r;
        for(int i = 0; i<n; i++){
            cin>>a[i];
            n2r[a[i]] += 1;
        }
        vector<int> f;
        for(auto pr : n2r){
            f.push_back(pr.second);
        }
        sort(f.begin(), f.end(), greater<int>());
        int ans = 0;
        if(k == 0){
            cout<<n2r.size()<<endl;
        }
        else if(k == n){
            cout<<1<<endl;
        }
        else{
            if((n - f[0]) %k !=0){
                ans = ((n - f[0])/k)  + 1;
            }
            else{
                ans = (n - f[0])/k;
            }

            cout<<ans<<endl;
        }

    }
    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; // number of test cases
    cin >> t;
    while (t--) {
        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> fq;
        fq.push_back(1);
        for(int i = 1; i<n; i++){
            if(a[i] == a[i-1]){
                fq.back()++;
            }
            else{
                fq.push_back(1);
            }
        }
        sort(fq.begin(), fq.end());
        int s = fq.size();
        bool done = false;
        int tk = k;
        for(int i = 0; i<s-1; i++){

            if(fq[i] > k){
                cout<<s-i<<endl;
                done = true;
                break;
            }
            k -= fq[i];
        }
        if(!done){
            cout<<1<<endl;
        }

    }
    return 0;
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
void solve(){
    int n,k;cin>>n>>k;
    vector<int>a(n);
    vector<int>cnt={1};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            cnt.back()++;
        }
        else{
            cnt.emplace_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    for(int i=0;i<cnt.size()-1;i++){
        if(cnt[i]>k){
            cout<<cnt.size()-i<<'\n';
            return;
        }
        k-=cnt[i];
    }
    cout<<1<<'\n';
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
void solve(){
    int n,k;cin>>n>>k;
    vector<int>a(n);
    vector<int>cnt(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(k>=n)cout<<1<<'\n';
    else{
        sort(a.begin(),a.end());
        int j=0;
        for(int i=0;i<n;){
            while(a[j]==a[i]){
                cnt[j]++;
                i++;
            }
            j++;
        }
        int ans=0;
        sort(cnt.begin(),cnt.begin()+j);
        for(int i=0;i<cnt.size();i++){
            if(cnt[i])ans++;
        }

        for(int i=0;i<cnt.size();i++){
            if(cnt[i]!=0&&k>=cnt[i]){
                k-=cnt[i];
                ans--;
            }
        }
        cout<<ans<<'\n';
    }
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Answer: 1


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

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

    unordered_map<int, int> mp;
    for(int i = 0; i < n; i++) {
        int el;
        cin >> el;

        mp[el]++;
    }

    if(k == n || k == n-1){
        cout << 1 << '\n';
        return ;
    }

    vector<int> a;
    for(auto [i, cnt] : mp){
        a.push_back(cnt);
    }

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

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

        if(k <= 0) {
            cnt++;
            continue;
        }

        if(a[i] >= k){
            a[i] -= k;
            k = 0;
        }else{
            k -= a[i];
            a[i] = 0;
        }

        if(a[i] != 0) {
            cnt++;
        }
    }

    cout << cnt << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

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

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

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

    if(k == n || k == n-1){
        cout << 1 << '\n';
        return ;
    }

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

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

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

        if(k <= 0) {
            cnt++;
            continue;
        }

        if(b[i] >= k){
            b[i] -= k;
            k = 0;
        }else{
            k -= b[i];
            b[i] = 0;
        }

        if(b[i] != 0) {
            cnt++;
        }
    }

    cout << cnt << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
    int t;
    cin >> t;

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.begin()+idx);

        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2 ++].first = 0;
            }
        }

        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
    int t;
    cin >> t;

    while(t --)
    {
        int n,m;

        map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.end());
        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2].first = 0;
            }
            idx2 ++;
        }

        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }

    return 0;
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N=1e5+10;
int n,k;
void solve(){
	scanf("%d%d",&n,&k);
	map<int,int> mp;
	int mx=0;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		mp[x]++;
	}
	vector<int> v;
	for(auto &a:mp) v.push_back(a.second);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++,k-=v[i]){
		if(k<v[i]){
			printf("%d\n",v.size()-i);
			return;
		}
	}
	puts("1");
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) solve();
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N=1e5+10;
int n,k;
void solve(){
	scanf("%d%d",&n,&k);
	map<int,int> mp;
	int mx=0;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		mp[x]++;
	}
	vector<int> v;
	for(auto &a:mp) v.push_back(a.second);
	sort(v.begin(),v.end());
	int m=v.size();
	for(int i=0;i<m-1;i++){
		if(k<v[i]){
			printf("%d\n",m-i);
			return;
		}
		k-=v[i];
	}
	puts("1");
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) solve();
}

Answer: 2


// inevitable -->> expert

/*

    $$$$$$$$       $$$      $$     $$       $$$       $$     $$     $$$$$$$$
       $$        $$   $$     $$   $$      $$   $$     $$$$   $$        $$
       $$        $$   $$      $$ $$       $$   $$     $$ $$  $$        $$
   $$  $$        $$$$$$$        $$        $$$$$$$     $$  $$ $$        $$
   $$  $$        $$   $$       $$         $$   $$     $$   $$$$        $$
   $$$$$$        $$   $$      $$          $$   $$     $$     $$        $$

*/

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

#define endl "\n"
#define spc " "
#define no cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define retno cout << "No" << endl; return;
#define retyes cout << "Yes" << endl; return;
#define ll long long
#define int long long
#define lli long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<long>
#define vll vector<long long>
#define vs vector<string>
#define pb push_back
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
// #define mp make_pair
#define mii map<int, int>
#define umii unordered_map<int, int>
#define maxHeap priority_queue<int>
#define minHeap priority_queue<int, vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf 1e18
#define all(x) x.begin(), x.end()
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define debug(x) cout << #x << " : " << x << endl;
#define fast_io                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define fr(a,b) for(auto i=a;i<b;++i)
#define frj(a,b) for(auto j=a;j<b;++j)
#define len(q) (int)(q.size())
#define traverse(arr)     \
	for (auto i : arr)    \
		cout << i << " "; \
	cout << "\n";
#define sortV(arr) sort(arr.begin(), arr.end())
const int mod = 1e9+7;
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF (( 1LL << 62 )-( 1LL << 31 )) /*Without overflow a large number*/
#define MOD 1000000007
#define SUM(x) accumulate(x.begin(), x.end(), 0LL)
#define debugMp(mp) for(auto i : mp) {cout << i.first << " -> "; for(auto val : i.second) cout << val << " "; cout << endl;}
// Traverse 2D matrix
#define debugM(arr) 					\
	fr(0, arr.size()) {					\
		frj(0, arr[0].size()) 			\
			cout << arr[i][j] << " ";	\
		cout << endl;					\
	}

// ================================== take ip/op like vector,pairs directly!==================================
template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
// ===================================END Of the input module ==========================================

const auto start_time = std::chrono::high_resolution_clock::now();
void getExecutionTime()
{
	auto end_time = std::chrono::high_resolution_clock::now();
	std::chrono::duration<double, std::milli> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
}

// // --------------------------------------------------------------ordered_set headers
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// // eg: ordered_set st;

// // oset<int> s: s.find_by_order(k): Kth element in 's', s.order_of_key(k): number of items strictly less than k
// template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// // eg: oset<int> st;
// // --------------------------------------------------------------END of ordered_set headers

// --------------------------------------------- SIEVE
pair<vi, vi> sieve(int n)
{
	vector<int> vis(n+1, true);
    for (int p = 2; p * p <= n; p++) {
        if (vis[p] == true) {
            for (int i = p * p; i <= n; i += p)
                vis[i] = false;
        }
    }
	vector<int> prime;
    for (int p = 2; p <= n; p++)
        if (vis[p])
            prime.push_back(p);
	return {vis, prime};
}

// ----------------------------------------GCD
int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a*b / gcd(a, b);
}

// ------------------------------- custom hash
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {

        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

// ------------------------------------------------------------------------------------------------------------------------------

// // to lower
// cout << char('A' | (1<<5)) << endl;
// cout << char('D' | ' ') << endl;

// // to upper
// cout << char('b' & '_') << endl;
// cout << char('a' & (~(1<<5))) << endl;

/*
// The Diplomat, the fall of the house of usher, daily dose of sunshine, blue eye samurai

	SPIDER-MAN: ACROSS THE SPIDER-VERSE
	--
	Mindhunter, jamtara, ocean 11, 12, 13,
	Movies - The pale blue eye, seven
	series - 1899, kaleidoscope
	andhadhun
	Murder in mahim
	castle
	Mentalist
	True detecative s1
	dark
	Narcos
	Lupin, Suzha - The vortex, Parking, Spycraft, Manifest (flight 828)
	Under the bridge
	sherlock, eric, hannibal
	The gentlemen,
	puss in boots
*/
// Mr. Robot, The Matrix, Source Code, Blackhat, Silicon Valley, The Internship

int getHash(string &s) {
	int p = 31, m = 1e9+7;
	int power = 1, hash = 0;
	for(int i = 0; i < len(s); i++) {
		hash = (hash + ((s[i]-'a'+1) * power)) % m;
		power = (power * p) % m;
	}

	return hash;
}

// arcjet -> rate limiting
void jayant() {
	int i, j, k, n, m, sum = 0;

	string s;
	// copy(arr.begin(), arr.end(), std::ostream_iterator<int>(std::cout, " "));
	// cout << ((double)clock() / CLOCKS_PER_SEC) << endl;

	cin >> n >> k;
	vi arr(n);
	cin >> arr;

	unordered_map<int, int> mp;
	for(auto i : arr) mp[i]++;

	vpii temp;
	for(auto i : mp) {
		temp.pb({i.second, i.first});
	}
	sortV(temp);

	i = 0;
	while(i < len(temp)-1) {
		if(k >= temp[i].first) k -= temp[i++].first;
		else break;
	}

	cout << len(temp)-i << endl;

}

// ---------------------------------------------- MAIN AREA -----------------------------------------------------------------

int32_t main()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	// if reads input from file
	// freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

	int t = 1;

	cin >> t;

	while(t--) {
		jayant();
	}
	getExecutionTime();
	return 0;
}

// sudo docker exec -it redis-stack-server redis-cli

// inevitable -->> expert

/*

    $$$$$$$$       $$$      $$     $$       $$$       $$     $$     $$$$$$$$
       $$        $$   $$     $$   $$      $$   $$     $$$$   $$        $$
       $$        $$   $$      $$ $$       $$   $$     $$ $$  $$        $$
   $$  $$        $$$$$$$        $$        $$$$$$$     $$  $$ $$        $$
   $$  $$        $$   $$       $$         $$   $$     $$   $$$$        $$
   $$$$$$        $$   $$      $$          $$   $$     $$     $$        $$

*/

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

#define endl "\n"
#define spc " "
#define no cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define retno cout << "No" << endl; return;
#define retyes cout << "Yes" << endl; return;
#define ll long long
#define int long long
#define lli long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<long>
#define vll vector<long long>
#define vs vector<string>
#define pb push_back
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
// #define mp make_pair
#define mii map<int, int>
#define umii unordered_map<int, int>
#define maxHeap priority_queue<int>
#define minHeap priority_queue<int, vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf 1e18
#define all(x) x.begin(), x.end()
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define debug(x) cout << #x << " : " << x << endl;
#define fast_io                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define fr(a,b) for(auto i=a;i<b;++i)
#define frj(a,b) for(auto j=a;j<b;++j)
#define len(q) (int)(q.size())
#define traverse(arr)     \
	for (auto i : arr)    \
		cout << i << " "; \
	cout << "\n";
#define sortV(arr) sort(arr.begin(), arr.end())
const int mod = 1e9+7;
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF (( 1LL << 62 )-( 1LL << 31 )) /*Without overflow a large number*/
#define MOD 1000000007
#define SUM(x) accumulate(x.begin(), x.end(), 0LL)
#define debugMp(mp) for(auto i : mp) {cout << i.first << " -> "; for(auto val : i.second) cout << val << " "; cout << endl;}
// Traverse 2D matrix
#define debugM(arr) 					\
	fr(0, arr.size()) {					\
		frj(0, arr[0].size()) 			\
			cout << arr[i][j] << " ";	\
		cout << endl;					\
	}

// ================================== take ip/op like vector,pairs directly!==================================
template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
// ===================================END Of the input module ==========================================

const auto start_time = std::chrono::high_resolution_clock::now();
void getExecutionTime()
{
	auto end_time = std::chrono::high_resolution_clock::now();
	std::chrono::duration<double, std::milli> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
}

// // --------------------------------------------------------------ordered_set headers
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// // eg: ordered_set st;

// // oset<int> s: s.find_by_order(k): Kth element in 's', s.order_of_key(k): number of items strictly less than k
// template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// // eg: oset<int> st;
// // --------------------------------------------------------------END of ordered_set headers

// --------------------------------------------- SIEVE
pair<vi, vi> sieve(int n)
{
	vector<int> vis(n+1, true);
    for (int p = 2; p * p <= n; p++) {
        if (vis[p] == true) {
            for (int i = p * p; i <= n; i += p)
                vis[i] = false;
        }
    }
	vector<int> prime;
    for (int p = 2; p <= n; p++)
        if (vis[p])
            prime.push_back(p);
	return {vis, prime};
}

// ----------------------------------------GCD
int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a*b / gcd(a, b);
}

// ------------------------------- custom hash
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {

        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

// ------------------------------------------------------------------------------------------------------------------------------

// // to lower
// cout << char('A' | (1<<5)) << endl;
// cout << char('D' | ' ') << endl;

// // to upper
// cout << char('b' & '_') << endl;
// cout << char('a' & (~(1<<5))) << endl;

/*
// The Diplomat, the fall of the house of usher, daily dose of sunshine, blue eye samurai

	SPIDER-MAN: ACROSS THE SPIDER-VERSE
	--
	Mindhunter, jamtara, ocean 11, 12, 13,
	Movies - The pale blue eye, seven
	series - 1899, kaleidoscope
	andhadhun
	Murder in mahim
	castle
	Mentalist
	True detecative s1
	dark
	Narcos
	Lupin, Suzha - The vortex, Parking, Spycraft, Manifest (flight 828)
	Under the bridge
	sherlock, eric, hannibal
	The gentlemen,
	puss in boots
*/
// Mr. Robot, The Matrix, Source Code, Blackhat, Silicon Valley, The Internship

int getHash(string &s) {
	int p = 31, m = 1e9+7;
	int power = 1, hash = 0;
	for(int i = 0; i < len(s); i++) {
		hash = (hash + ((s[i]-'a'+1) * power)) % m;
		power = (power * p) % m;
	}

	return hash;
}

// arcjet -> rate limiting
void jayant() {
	int i, j, k, n, m, sum = 0;

	string s;
	// copy(arr.begin(), arr.end(), std::ostream_iterator<int>(std::cout, " "));
	// cout << ((double)clock() / CLOCKS_PER_SEC) << endl;

	cin >> n >> k;
	vi arr(n);
	cin >> arr;

	map<int, int> mp;
	for(auto i : arr) mp[i]++;

	vpii temp;
	for(auto i : mp) {
		temp.pb({i.second, i.first});
	}
	sortV(temp);

	i = 0;
	while(i < len(temp)-1) {
		if(k >= temp[i].first) k -= temp[i++].first;
		else break;
	}

	cout << len(temp)-i << endl;

}

// ---------------------------------------------- MAIN AREA -----------------------------------------------------------------

int32_t main()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	// if reads input from file
	// freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

	int t = 1;

	cin >> t;

	while(t--) {
		jayant();
	}
	getExecutionTime();
	return 0;
}

// sudo docker exec -it redis-stack-server redis-cli

Answer: 2


import sys
from collections import Counter

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")

def solve(test_case):
    N,K = multi_int_input()
    arr = list_input()

    check = Counter()
    for i in arr:
        check[str(i)] += 1
    check = sorted(check.values(),reverse=True)

    while check:
        if check[-1] <= K:
            K -= check.pop()
        else:
            break

    P1(max(1,len(check)))

tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))

import sys
from collections import Counter

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")

def solve(test_case):
    N,K = multi_int_input()
    arr = list_input()

    check = sorted(Counter(arr).values(),reverse=True)

    while check:
        if check[-1] <= K:
            K -= check.pop()
        else:
            break

    P1(max(1,len(check)))

tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))

Answer: 1


// Gorilla and the exam

import java.util.*;

public class _2057B {
    public static void sovle(int k, int arr[]) {
        Arrays.sort(arr);
        List<Integer> cnt = new ArrayList<>();
        cnt.add(1);
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] == arr[i - 1]) {
                cnt.set(cnt.size() - 1, cnt.get(cnt.size() - 1) + 1);
            } else {
                cnt.add(1);
            }
        }

        Collections.sort(cnt);
        int m = cnt.size();
        for (int i = 0; i < m - 1; i++) {
            if (cnt.get(i) > k) {
                System.out.println(m - i);
                return;
            }
            k -= cnt.get(i);
        }
        System.out.println(1);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();

            int arr[] = new int[n];

            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }

            sovle(k, arr);

            t--;
        }
        sc.close();
    }
}

// Gorilla and the exam

import java.util.*;

public class _2057B {
    public static void sovle(int k, int arr[]) {
        Arrays.sort(arr);
        List<Integer> cnt = new ArrayList<>();
        cnt.add(1);
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] == arr[i - 1]) {
                cnt.set(cnt.size() - 1, cnt.get(cnt.size() - 1) + 1);
            } else {
                cnt.add(1);
            }
        }

        Collections.sort(cnt);
        for (int i = 0; i < cnt.size(); i++) {
            System.out.println(cnt.get(i));
        }
        int m = cnt.size();
        for (int i = 0; i < m - 1; i++) {
            if (cnt.get(i) > k) {
                System.out.println(m - i);
                return;
            }
            k -= cnt.get(i);
        }
        System.out.println(1);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();

            int arr[] = new int[n];

            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }

            sovle(k, arr);

            t--;
        }
        sc.close();
    }
}

Answer: 1


//
// Created by bahab on 7/24/2024.
//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#ifndef ONLINE_JUDGE
#endif

const long long mod=1e9+7;
const long long MOD=998244353;
#define ll long long
#define endl '\n'
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define INF 1e18+5
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define bahab(x) cout << x
#define lb cout << endl;
#define show(x) for (auto it : x) cout << it << " "

ll binpow(ll a,ll b){ll res=1;while(b>0){if(b&1)res=(res*a);a=((a)*(a));b/=2;}return res;}
ll gcd(ll a,ll b){return b==0 ? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}
ll comb(ll n, ll k) {
    if (k > n) return 0;
    if (k == 0 || k == n) return 1;
    if (k == 1) return n;
    ll result = 1;
    for (ll i = 1; i <= k; ++i) { result *= (n - i + 1) / i; }
    return result;
}
// -----------------------------------------------------------------------

void solve(){
    int n, k; cin >> n >> k;
    vector<ll> arr(n);
    for (int i = 0 ; i < n ; i ++)
        cin >> arr[i];
    sort(all(arr));
    vector<int> mp = {1};
    for (int i = 1 ; i < n ; i ++){
        if (arr[i] == arr[i - 1])
            mp.back()++;
        else mp.pb(1);
    }
    sort(all(mp));
//    show(mp); cout << endl;
    int sz = mp.size(), ind = 0;
    for (int i = 0 ; i < sz ; i ++){
        if (mp[i] > k){
            break;
        }
        else {
            ind++;
            k -= mp[i];
        }
    }
    cout << max(sz - ind, 1) << endl;
}
// -----------------------------------------------------------------------

int main (){
    FAST;
    int tc = 1;
    cin >> tc;
    while (tc --)
        solve();
}

//
// Created by bahab on 7/24/2024.
//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#ifndef ONLINE_JUDGE
#endif

const long long mod=1e9+7;
const long long MOD=998244353;
#define ll long long
#define endl '\n'
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define INF 1e18+5
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define bahab(x) cout << x
#define lb cout << endl;
#define show(x) for (auto it : x) cout << it << " "

ll binpow(ll a,ll b){ll res=1;while(b>0){if(b&1)res=(res*a);a=((a)*(a));b/=2;}return res;}
ll gcd(ll a,ll b){return b==0 ? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}
ll comb(ll n, ll k) {
    if (k > n) return 0;
    if (k == 0 || k == n) return 1;
    if (k == 1) return n;
    ll result = 1;
    for (ll i = 1; i <= k; ++i) { result *= (n - i + 1) / i; }
    return result;
}
// -----------------------------------------------------------------------

void solve(){
    int n, k; cin >> n >> k;
    vector<ll> arr(n);
    vector<pair<int, ll>> p;
    unordered_map<ll,int> mp;
    for (int i = 0; i < n ; i++){
        cin >> arr[i];
        mp[arr[i]]++;
    }
    int sz = mp.size();
    vector<ll> pref(sz + 1);
    for (auto it : mp){
        p.emplace_back(it.second, it.first);
    }
    sort(all(p));
//    for (auto iter : p) cout << iter.F << " , " << iter.S << " || ";
//    cout << endl;
    for (int i = 1 ; i <= mp.size(); i ++){
        pref[i] = pref[i - 1] + p[i - 1].first;
    }
//    show(pref);
//    cout << endl;
    int ind = lower_bound(all(pref), k) - pref.begin();
    if (pref[ind] > k){
        ind--;
    }
    cout << max(sz - ind, 1) << endl;
}
// -----------------------------------------------------------------------

int main (){
    FAST;
    int tc = 1;
    cin >> tc;
    while (tc --)
        solve();
}

Answer: 1


#include<iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int t ; cin>>t;
    while(t--){
        int n , k ; cin>>n>>k ;
        vector<int> a ;
        map<int,int> m ;
        for(int i = 0 ; i< n ; i++) {
            int x ; cin>>x ;
            a.push_back(x);
            m[x]++ ;
        }
        vector<int> x ;
        for(auto i : m){
            x.push_back(i.second);
        }
        sort(x.begin() , x.end());
        int ans = x.size();
        for(auto i : x){
            if(k >= i){
                ans--;
                k-=i;
            }
        }
        cout<<ans<<endl;

    }
    return 0 ;
}

#include<iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int t ; cin>>t;
    while(t--){
        int n , k ; cin>>n>>k ;
        vector<int> a ;
        map<int,int> m ;
        for(int i = 0 ; i< n ; i++) {
            int x ; cin>>x ;
            a.push_back(x);
            m[x]++ ;
        }
        vector<int> x ;
        for(auto i : m){
            x.push_back(i.second);
        }
        sort(x.begin() , x.end());
        int ans = x.size();
        for(auto i : x){
            if(k >= i){
                ans--;
                k-=i;
            }
        }
        cout<<max(ans,1)<<endl;

    }
    return 0 ;
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a, a + n);
        int y = a[0];
        int countt = 1;
        int b[n] = {0};
        for (int i = 1; i < n; i++)
        {
            if(y == a[i])
            {
                countt++;
            }
            else
            {
                b[countt - 1]++;
                y = a[i];
                countt = 1;
            }
        }
        b[countt - 1]++;
        int ans = 0;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            ans += b[i];
        }
        // cout << ans << endl;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            if(k == 0)
            {
                break;
            }
            if(k < b[i]*(i+1))
            {
                ans -= k/(i+1);
                k = 0;
            }
            else
            {
                k -= b[i]*(i+1);
                ans -= b[i];
            }
        }
        if(ans == 0)
        {
            ans = 1;
        }
        cout << ans << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a, a + n);
        int y = a[0];
        int countt = 1;
        int b[n] = {0};
        for (int i = 1; i < n; i++)
        {
            if(y == a[i])
            {
                countt++;
            }
            else
            {
                b[countt - 1]++;
                y = a[i];
                countt = 1;
            }
        }
        b[countt - 1]++;
        int ans = 0;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            ans += b[i];
        }
        // cout << ans << endl;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            if(k == 0)
            {
                break;
            }
            if(k < b[i])
            {
                ans -= k;
            }
            else
            {
                k -= b[i]*(i+1);
                ans -= b[i];
            }
        }
        if(ans == 0)
        {
            ans = 1;
        }
        cout << ans << endl;
    }
    return 0;
}

Answer: 1


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class TestFile {
	public static void main(String[]args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		while( t-- > 0) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int[] arr = new int[n];
			HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
			for(int i=0;i<n;i++) {
				arr[i] = scanner.nextInt();
				if(map.containsKey(arr[i])) {
					map.put(arr[i], map.get(arr[i]) + 1);
				} else {
					map.put(arr[i], 1);
				}
			}
			if(k == 0) {
				System.out.println(map.size());
				continue;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(Map.Entry<Integer, Integer> elEntry : map.entrySet()) {
				list.add(elEntry.getValue());
			}
			list.sort(null);
			//System.out.println(list);
			int count = 1;
			for(int i=0;i<list.size();i++) {
				if(k >= list.get(i)) {
					k -= list.get(i);
					list.set(i, 0);
				} else {
					count = list.size() - i;
					break;
				}
			}
			System.out.println(count);
		}
		scanner.close();
	}

}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class TestFile {
	public static void main(String[]args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		while( t-- > 0) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int[] arr = new int[n];
			HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
			for(int i=0;i<n;i++) {
				arr[i] = scanner.nextInt();
				if(map.containsKey(arr[i])) {
					map.put(arr[i], map.get(arr[i]) + 1);
				} else {
					map.put(arr[i], 1);
				}
			}
			if(k == 0) {
				System.out.println(map.size());
				continue;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(Map.Entry<Integer, Integer> elEntry : map.entrySet()) {
				list.add(elEntry.getValue());
			}
			list.sort(null);
			System.out.println(list);
			int count = 1;
			for(int i=0;i<list.size();i++) {
				if(k >= list.get(i)) {
					k -= list.get(i);
					list.set(i, 0);
				} else {
					count = list.size() - i;
					break;
				}
			}
			System.out.println(count);
		}
		scanner.close();
	}

}

Answer: 1


/*
 * Gorrila and the Exam
 * 18.01.24
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

// calc total subarrays with same element -> calc subarrays whose sum of lenth is equal to p -> subtract
int solve(int n, int k, vector<int>& a){

    unordered_map<int, int> mp;
    for(int i = 0; i < a.size(); i++){
        mp[a[i]]++;
    }
    vector<int> fq;
    for(auto& a: mp){
        fq.push_back(a.second);
    }

    sort(fq.begin(), fq.end());
    int m = fq.size();
    int ans = 0;
    for(int i = 0; i < m-1; i++){
        if(fq[i] > k){
            return m - i;
            k = 0;
        }
        else {
            k -= fq[i];
        }
    }
    return 1;

}

int main(){
    int tc;
    cin >> tc;
    while(tc--){
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];
        int ans = solve(n, k, a);
        cout << ans << endl;
    }

    return 0;
}

/*
 * Gorrila and the Exam
 * 18.01.24
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

// calc total subarrays with same element -> calc subarrays whose sum of lenth is equal to p -> subtract
int solve(int n, int k, vector<int>& a){

/*
    unordered_map<int, int> mp;
    for(int i = 0; i < a.size(); i++){
        mp[a[i]]++;
    }

    Using a vector instead of unordered_map is more efficient
    due to reduced overhead and better memory locality, avoiding hash collision
*/
    sort(a.begin(), a.end());
    vector<int> cnt = {1};

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

    sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    int ans = 0;
    for(int i = 0; i < m-1; i++){
        if(cnt[i] > k){
            return m - i;
            k = 0;
        }
        else {
            k -= cnt[i];
        }
    }
    return 1;

}

int main(){
    int tc;
    cin >> tc;
    while(tc--){
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];
        int ans = solve(n, k, a);
        cout << ans << endl;
    }

    return 0;
}

Answer: 2


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

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    int ele = mp.size();
    if(ele >= k){
        return 1;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}

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

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(!pq.empty() && k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.empty() ? 1 : pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}

Answer: 2