#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void solve()
{
	int n,k;cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	vector<int>b(1,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 m=b.size();
	for(int i=0;i<m;i++)
	{
		if(b[i]>k)
		{
			cout<<m-i<<endl;return;
		}
		k-=b[i];
	}
	cout<<"1"<<endl;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int t;cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void solve()
{
	int n,k;cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	vector<int>b(1,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 m=b.size();
	for(int i=0;i<m;i++)
	{
		if(b[i]>k)
		{
			cout<<m-i<<endl;return;
		}
		k-=b[i];
	}
	cout<<"1"<<endl;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(false);
	int t;cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Answer: 1


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<unordered_map>
using namespace std;
void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector <int>q(n);
        unordered_map<int, int>q1;
        for (int i = 0; i < n; i++) {
            cin >> q[i];
            q1[q[i]]++;
        }
        vector<int>q2;
        for (const auto x : q1) {
            q2.push_back(x.second);
        }
        int a = q2.size();
        sort(q2.begin(), q2.end());
        for (int i = 0; i < q2.size(), i++) {
            if (q2[i] <= k) {
                k -= q2[i];
                a--;
            }
        }
        cout << max(1, a) << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
const int mod = 1e9+10;
int n,m,q,k;
void solve(){
    cin>>n>>k;
    vector<int>v(n);
    map<int,int>mp;
    for (int i =0;i<n;i++) {
        cin>>v[i];
        mp[v[i]]++;
    }
    int cnt =0;
    vector<pair<int,int>>pa;
    for (auto i:mp) {
        pa.push_back({i.second,i.first});
    }
    sort(all(pa));
    for (int i =0;i<pa.size()-1;i++) {
        if (pa[i].first<=k) {
            cnt++;
            k-=pa[i].first;
        }
    }
    cout<<mp.size()-cnt<<endl;
}
signed main(){
    int t  =1;
    cin>>t;
    while(t--){
        solve();
    }
}

Answer: 2


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

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() > k)
                break;
            k -= v.back();
            v.pop_back();
        }
        cout <<  max((int)v.size(), 1) << endl;
    }
    return 0;
}

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

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        unordered_map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0) {
            if(v.back() <= k) {
                k -= v.back();
                v.pop_back();
            }
        }
        cout <<  max((int)v.size(), 1LL) << endl;
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
// using u128 = unsigned __int128;

void solve() {
    std::unordered_map<int, int> cnt;
    std::vector<int> data;
    int n, k;
    std::cin >> n >> k;

    for(int i = 0; i < n; ++i){
        int x;
        std::cin >> x;
        cnt[x]++;
    }

    for(auto [x, c] : cnt){
        data.push_back(c);
    }

    std::sort(data.begin(), data.end());

    int i = 0;

    int ans = data.size();

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

    std::cout << ans << std::endl;
}

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

    int t;
    std::cin >> t;

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

    return 0;
}

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
//using u128 = unsigned __int128;

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

    std::map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        cnt[a]++;
    }

    std::vector<int> c;
    for (auto [_, x] : cnt) {
        c.push_back(x);
    }
    std::sort(c.begin(), c.end());
    int ans = c.size();
    for (int i = 0; i < c.size() - 1; i++) {
        if (k >= c[i]) {
            ans--;
            k -= c[i];
        }
    }
    std::cout << ans << "\n";
}

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

    int t;
    std::cin >> t;

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

    return 0;
}

Answer: 2


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int t;cin>>t;
	while(t--){
		int n,k;cin>>n>>k;
		int st[n],sp[n]={0};
		for(int i=0;i<n;i++){
			cin>>st[i];
		}
		sort(st,st+n);
		int p=0;
		sp[0]=1;
		for(int i=1;i<n;i++){
			if(st[i]==st[i-1]){
				sp[p]+=1;
			}
			else{
				p++;
				sp[p]=1;
			}
		}
		sort(sp,sp+p);
		int ss=p;
		while(k>0&&p>=0){
			k=k-sp[ss-p];
			p--;
		}
		p++;
		if(p<=1) p=1;
		cout<<p<<endl;
	}

	return 0;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int t;cin>>t;
	while(t--){
		int n,k;cin>>n>>k;
		int st[n],sp[n]={0};
		for(int i=0;i<n;i++){
			cin>>st[i];
		}
		sort(st,st+n);
		int p=0;
		sp[0]=1;
		for(int i=1;i<n;i++){
			if(st[i]==st[i-1]){
				sp[p]+=1;
			}
			else{
				p++;
				sp[p]=1;
			}
		}
		p++;
		sort(sp,sp+p);
		for(int i=0;i<p;i++){
			//cout<<sp[i]<<"|";
		}
		int ss=p;
		while(k>0){
			if(p==0){
				break;
			}
			if(k>=sp[ss-p]){
				k=k-sp[ss-p];
			}
			else{
				break;
			}
			p--;
		}
		if(p<=1) p=1;
		cout<<p<<endl;
	}

	return 0;
}

Answer: 2


#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
    map<int,int> times;
    int t,n,k,num,st=0;
    cin >>t;
    for (int i=0;i<t;i++){
        cin >>n>>k;
        for (int j=0;j<n;j++){
        cin>>num;
        if (times[num]==0) {
            times[num]=1;
            st++;     }
        else times[num]++;
        }
        multiset<int> s;
        for (auto &pair : times) {
                s.insert(pair.second);
            }
        for (int x:s){
            if (x>k) break;
            else {
                k=k-x;
                st--;
            }
        }
        if (st!=0)cout <<st<<endl;
        else cout << "1"<<endl;
        s.clear();
        times.clear();
        n=0;k=0;num=0;st=0;
    }
}

#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
    map<int,int> times;
    int t,n,k,num,st=0;
    cin >>t;
    for (int i=0;i<t;i++){
        cin >>n>>k;
        for (int j=0;j<n;j++){
        cin>>num;
        if (times[num]==0) {
            times[num]=1;
            st++;     }
        else times[num]++;
        }
        multiset<int> s;
        for (auto &pair : times) {
                s.insert(pair.second);
            }
        for (int x:s){
            if ((x>k)||((x==1)&&(k==1))) break;
            else {
                k=k-x;
                st--;
            }
        }

        cout <<st<<endl;
        s.clear();
        times.clear();
        n=0;k=0;num=0;st=0;
    }
}

Answer: 1


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

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

    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        vector<int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums.push_back(x); }
        vector<int> freq;
        sort(nums.begin(), nums.end());
        int last = -1, f = 0;
        for(int n : nums){
            if(last == -1){ last = n; f++; }
            else if(last == n){ f++; }
            else{ last = n; freq.push_back(f); f = 1;}
        }
        freq.push_back(f);
        sort(freq.begin(), freq.end());
        int i = 0;
        while(i < freq.size()-1){
            if(m < freq[i]){ break; }
            m -= freq[i]; i++;
        }
        cout << freq.size() - i << '\n';
    }
}

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

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        int n, m; cin >> n >> m;
        unordered_map<int, int> nums;
        for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; }
        vector<int> freq;
        int i = 0, removed = 0, greatest = 0;
        for(auto& [key, val] : nums){ freq.push_back(val); greatest = max(greatest, val); }
        bool runThrough = false;
        while(i < freq.size()){
            if(m < freq[i]){ i++; continue; }
            if(freq[i] == greatest){ if(!runThrough){ runThrough = true; i++; continue; } }
            m -= freq[i]; removed++; i++;
        }
        cout << freq.size() - removed << '\n';
    }
}

Answer: 1


# include <bits/stdc++.h>
using namespace std;
# define no cout <<"NO" << endl
# define yes cout << "YES"<< endl
# define ll long long int
# define flp(i,k,n) for(ll i = k;i<n;i++)
# define rflp(i,k,n) for(ll i = k-1;i>=n;i--)
# define i(a) ll a;cin >> a;
# define ic(i) char i;cin >> i;
# define ia(a,n) ll a[n];for(ll i=0;i<n;i++)cin >> a[i];
# define ica(a,n) char a[n];for(ll i=0;i<n;i++)cin >> a[i];
# define is(s) string s;cin >> s;
# define mod 1000000007
# define dv 1000000000

// bool isPrime(int n)
// {
//     if (n <= 1)
//         return false;

//     for (int i = 2; i <= sqrt(n); i++)
//         if (n % i == 0)
//             return false;

//     return true;
// }

// void dfs(ll node,ll iter,int ind,vector<queue<pair<ll,ll>>>& v,set <ll> &s,ll &sum){
//     s.insert(node);
//     // cout << "node-->" << node <<"  iter-->" << iter<< endl;
//     ll w=0;
//     while(!v[node-1].empty()){
//         ll u=iter;
//         ll t1=v[node-1].front().first;
//         ll t2=v[node-1].front().second;
//         // cout << t1 << " " << t2 << endl;
//         if(s.find(t1)!=s.end()){
//             v[node-1].pop();
//             continue;
//         }
//         else{
//             if(t2<ind)u++;
//             sum=max(sum,u);
//             // cout << "iter-->"<< iter << " sum" << sum<< endl;
//             dfs(t1,u,t2,v,s,sum);
//         }
//         v[node-1].pop();
//     }
// }

// bool comp(pair<ll,ll> p1 ,pair<ll,ll> p2){
//     if(p1.second==p2.second)return p1.first>p2.first;
//     else return p1.second < p2.second;
// }

void solve(){
    i(n);
    i(k);
    ia(arr,n);

    map <ll,ll> m;
    flp(i,0,n){
        m[arr[i]]++;
    }

    ll a[m.size()];
    int j=0;
    for(auto i:m){
        a[j++]=i.second;
    }
    sort(a,a+m.size());
    if(k==0){
            cout << m.size() << endl;
            return;
    }
    flp(i,0,m.size()){
        if(k<=0){
            cout << m.size()-i << endl;
            return;
        }
        else{
            k-=a[i];
        }
    }
    cout << 1 << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    cin >> t;
    while(t--)solve();
}

# include <bits/stdc++.h>
using namespace std;
# define no cout <<"NO" << endl
# define yes cout << "YES"<< endl
# define ll long long int
# define flp(i,k,n) for(ll i = k;i<n;i++)
# define rflp(i,k,n) for(ll i = k-1;i>=n;i--)
# define i(a) ll a;cin >> a;
# define ic(i) char i;cin >> i;
# define ia(a,n) ll a[n];for(ll i=0;i<n;i++)cin >> a[i];
# define ica(a,n) char a[n];for(ll i=0;i<n;i++)cin >> a[i];
# define is(s) string s;cin >> s;
# define mod 1000000007
# define dv 1000000000

// bool isPrime(int n)
// {
//     if (n <= 1)
//         return false;

//     for (int i = 2; i <= sqrt(n); i++)
//         if (n % i == 0)
//             return false;

//     return true;
// }

// void dfs(ll node,ll iter,int ind,vector<queue<pair<ll,ll>>>& v,set <ll> &s,ll &sum){
//     s.insert(node);
//     // cout << "node-->" << node <<"  iter-->" << iter<< endl;
//     ll w=0;
//     while(!v[node-1].empty()){
//         ll u=iter;
//         ll t1=v[node-1].front().first;
//         ll t2=v[node-1].front().second;
//         // cout << t1 << " " << t2 << endl;
//         if(s.find(t1)!=s.end()){
//             v[node-1].pop();
//             continue;
//         }
//         else{
//             if(t2<ind)u++;
//             sum=max(sum,u);
//             // cout << "iter-->"<< iter << " sum" << sum<< endl;
//             dfs(t1,u,t2,v,s,sum);
//         }
//         v[node-1].pop();
//     }
// }

// bool comp(pair<ll,ll> p1 ,pair<ll,ll> p2){
//     if(p1.second==p2.second)return p1.first>p2.first;
//     else return p1.second < p2.second;
// }

void solve(){
    i(n);
    i(k);
    ia(arr,n);

    map <ll,ll> mp;
    flp(i,0,n){
        mp[arr[i]]++;
    }
    vector<int> v;
    for(auto i:mp){
        v.push_back(i.second);
    }
    int l = v.size();
    sort(v.begin(),v.end());
    if(k>=n){
        cout << 1 << endl;
        return;
    }
    else{
        flp(i,0,l){
            if(k-v[i]>=0){
                k-=v[i];
            }
            else{
                cout << l-i << endl;
                return;
            }
        }
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    cin >> t;
    while(t--)solve();
}

Answer: 2


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

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

    map<int, int> mp;

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

    vector<int> arr;
    for (auto it : mp)
    {
        int first = it.first;
        int second = it.second;

        arr.push_back(second);
    }

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

    int ans = (int)mp.size();
    for (int i = 0; i < arr.size(); i++)
    {
        if (k - arr[i] >= 0)
        {
            k = k - arr[i];
            ans--;
        }
        else
            break;
    }
    return max(ans, 1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--)
        cout << solve() << endl;

    return 0;
}

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

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

    unordered_map<int, int> mp;

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

    vector<int> arr;
    for (auto it : mp)
    {
        int first = it.first;
        int second = it.second;

        arr.push_back(second);
    }

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

    int ans = (int)mp.size();
    for (int i = 0; i < n; i++)
    {
        if (k - arr[i] >= 0)
        {
            k = k - arr[i];
            ans--;
        }
        else
            break;
    }
    return max(ans, 1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--)
        cout << solve() << endl;

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction(a) cout.unsetf(ios::floatfield);cout.precision(a);cout.setf(ios::fixed,ios::floatfield);
#define ll long long
#define endl '\n'
#define gap " "
#define bug(a) cerr<< #a << " : " << a <<endl
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define tc ll t; cin>>t; while(t--)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a*b)/(__gcd(a,b)))
const ll mod = 1000000007;
const double pi= acos(-1);
const int n=2*(1e5+10);
int main()
{
    optimize()
    tc
    {
        ll n,k;
        cin>>n>>k;
        vector<ll>v(n),v1;
        ll i;
        map<ll,ll>cnt;
        for(i=0;i<n;i++){
            cin>>v[i];
            cnt[v[i]]++;
        }
        ll n1=cnt.size();
        //bug(n1);
        ll c1=0;
        for(auto u:cnt){
           v1.pb(u.second);
        }
        sort(all(v1));
        for(i=0;i<n1;i++){
            if(v1[i]<=k){
                k-=v1[i];
                c1++;
            }
            else break;
        }
        if(c1==n1)cout<<0<<endl;
        else
        {
            cout<<n1-c1<<endl;
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction(a) cout.unsetf(ios::floatfield);cout.precision(a);cout.setf(ios::fixed,ios::floatfield);
#define ll long long
#define endl '\n'
#define gap " "
#define bug(a) cerr<< #a << " : " << a <<endl
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define tc ll t; cin>>t; while(t--)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a*b)/(__gcd(a,b)))
const ll mod = 1000000007;
const double pi= acos(-1);
const int n=2*(1e5+10);
int main()
{
    optimize()
    tc
    {
        ll n,k;
        cin>>n>>k;
        vector<ll>v(n),v1;
        ll i;
        map<ll,ll>cnt;
        for(i=0;i<n;i++){
            cin>>v[i];
            cnt[v[i]]++;
        }
        ll n1=cnt.size();
        //bug(n1);
        ll c1=0;
        for(auto u:cnt){
           v1.pb(u.second);
        }
        sort(all(v1));
        for(i=0;i<n1;i++){
            if(v1[i]<=k){
                k-=v1[i];
                c1++;
            }
            else break;
        }
        if(c1==n1)cout<<1<<endl;
        else
        {
            cout<<n1-c1<<endl;
        }
    }
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        unordered_map<int, int> mpp;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            mpp[a[i]]++;

        }
        int count = 0;
        int maxi = 1e10;
        vector<int> freq;
        for (auto it : mpp)
        {
            count++;
            maxi = max(maxi, it.second);
            freq.push_back(it.second);
        }
        sort(freq.begin(), freq.end());
        for (int i = 0; i < freq.size(); i++)
        {
            if (freq[i] <= k)
            {
                k -= freq[i];
                count--;
            }
            if(k<0) break;
        }
        if (count == 0)
            cout << 1 << endl;
        else
            cout << count << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        int n, k;
        cin >> n >> k;
        int x;
        map<int, int> mpp;
        for (int i = 0; i < n; i++)
        {
            cin >> x;
            mpp[x]++;

        }
        int count = 0;
        vector<int> freq;
        for (auto it : mpp)
        {
            count++;
            freq.push_back(it.second);
        }
        sort(freq.begin(), freq.end());
        for (int i = 0; i < freq.size(); i++)
        {
            if (freq[i] <= k)
            {
                k -= freq[i];
                count--;
            }
            if(k<0) break;
        }
        if (count == 0)
            cout << 1 << endl;
        else
            cout << count << endl;
    }
    return 0;
}

Answer: 2


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

int main(){
    int t,n,k;
    long long a;
    vector<long long> nums;
    cin>>t;
    while(t--){
        cin>>n>>k;
        nums.resize(n);
        map<long long,int> mp;
        set<pair<int,long long>> st;
        for(int i=0;i<n;i++){
            cin>>nums[i];
            mp[nums[i]]++;
        }
        for(auto it : mp){
            st.insert({it.second,it.first});
        }

        while(k){
            auto it=*st.begin();
            if(k<it.first)  break;
            st.erase(st.begin());

            k-=it.first;

        }
        int size=st.size();
        cout<<max(1,size)<<endl;
    }
    return 0;
}

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

int main(){
    int t,n,k,a;
    vector<int> nums;
    cin>>t;
    while(t--){
        cin>>n>>k;
        nums.resize(n);
        map<long long,int> mp;
        set<pair<int,long long>> st;
        for(int i=0;i<n;i++){
            cin>>nums[i];
            mp[nums[i]]++;
        }
        for(auto it : mp){
            st.insert({it.second,it.first});
        }

        while(k){
            auto it=*st.begin();
            st.erase(st.begin());
            if(k<it.first)  break;
            k-=it.first;

        }
        int size=st.size();
        cout<<max(1,size)<<endl;
    }
    return 0;
}

Answer: 1


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

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

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

    sort(a.begin(), a.end());
    vector<int> 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 - 1; i++) {
        if (cnt[i] > k) {
            cout << m - i << "\n";
            return;
        }
        k -= cnt[i];
    }
    cout << 1 << "\n";
}

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

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

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

int main() {
    fast_io;
    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];
        }

        // Step 1: Calculate frequencies
        int max_val = *max_element(arr.begin(), arr.end());
        vector<int> freq(max_val + 1, 0);
        for (int num : arr) {
            freq[num]++;
        }

        // Step 2: Remove zeros and sort frequencies
        vector<int> counts;
        for (int count : freq) {
            if (count > 0) {
                counts.push_back(count);
            }
        }
        sort(counts.begin(), counts.end()); // Sort by frequency (ascending)

        // Step 3: Use k to reduce frequencies
        for (int i = 0; i < counts.size() && k > 0; ++i) {
            if (k >= counts[i]) {
                k -= counts[i]; // Use all occurrences of this element
                counts[i] = 0;  // Mark as removed
            } else {
                counts[i] -= k; // Reduce remaining frequency
                k = 0;          // All of k is used
            }
        }

        // Step 4: Count remaining distinct elements
        int cnt = 0;
        for (int count : counts) {
            if (count > 0) {
                cnt++;
            }
        }

        // If no distinct elements are left, output 1
        cout << (cnt == 0 ? 1 : cnt) << endl;
    }

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
constexpr int mod=(int)2*1e5+7;
bool ct=false;

inline void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    unordered_map<int,int>m;
    vector<int>s;
    for(auto it:v){
      cin>>it;
      m[it]++;
    }
    for(auto it:m){
      s.push_back(it.second);
    }
    sort(s.begin(),s.end());
    int ans=k;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]<=ans) ans-=s[i],c++;
        else break;
    }
    if((s.size()-c)==0) cout<<1<<"\n";
    else cout<<s.size()-c<<"\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t=1;
     cin>>t;
    while(t--) solve();
    return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
  你好,
  操你 母狗!!
*/

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

int solve(){
    int n,k,temp;
    cin>>n>>k;
    map<int, int> m;

    for(int i=0;i<n;i++){
        cin>>temp;
        m[temp]++;
    }
    vector<int> v;
    for(auto x:m){
        v.push_back(x.second);
    }
    sort(v.begin(),v.end());
    int ans=v.size();
    // cout<<"ans "<<ans<<endl;

    if(k==0){
        cout<<ans<<endl;
        return 0;
    }

    for(int i=0;i<v.size();i++){
        k-=v[i];
        if(k<0){
            break;
        }
        ans--;
    }
    cout<<max(ans,1)<<endl;
    return 0;
}
int main()
{
    int testCase=1;
    cin>>testCase;
    while(testCase--){
        solve();
    }
    return 0;
}

Answer: 2


#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i]){
			m-=num[i];
		}
		else{
			printf("%lld\n",s-i);
			flag=true;
			return;
		}
	}
	printf("1\n");
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int,int>mp;
int tot[200005];
int n,m,idt,x;
void solve(){
	idt=0;
	mp.clear();
	for(int i=1;i<=n;i++){
		tot[i]=0;
	}
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		if(mp[x]==0){
			mp[x]=++idt;
		}
		x=mp[x];
		tot[x]++;
	}
	int ans=idt;
	sort(tot+1,tot+idt+1);
	for(int i=1;i<idt;i++){
		if(m<=0)break;
		if(tot[i]<=m){
			m-=tot[i];
		}
		ans--;
	}
	printf("%lld\n",ans);
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Answer: 1


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

ll t, n, k, x, ans;
set<ll> a;
multiset<ll> b;
priority_queue <ll, vector<ll>, greater<ll>> pq;

int main() {
    cin >> t;
    for(ll T = 1; T <= t; T++) {
        cin >> n >> k;
        a.clear();
        b.clear();
        for(ll i = 1; i <= n; i++) {
            cin >> x;
            a.insert(x);
            b.insert(x);
        }
        ans = a.size();
        pq = priority_queue <ll, vector<ll>, greater<ll>>();
        for(ll i : a) {
            pq.push(b.count(i));
            cout << i << "/" << b.count(i) << " ";
        }
        cout << "\n";
        while(pq.size() > 1) {
            if(k >= pq.top()) {
                k -= pq.top();
                ans--;
                pq.pop();
            } else break;
        }
        cout << ans << "\n\n";
    }
}

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

ll t, n, k, x, ans;
set<ll> a;
multiset<ll> b;
priority_queue <ll, vector<ll>, greater<ll>> pq;

int main() {
    cin >> t;
    for(ll T = 1; T <= t; T++) {
        cin >> n >> k;
        a.clear();
        b.clear();
        for(ll i = 1; i <= n; i++) {
            cin >> x;
            a.insert(x);
            b.insert(x);
        }
        ans = a.size();
        pq = priority_queue <ll, vector<ll>, greater<ll>>();
        for(ll i : a) {
            pq.push(b.count(i));
        }
        while(pq.size() > 1) {
            if(k >= pq.top()) {
                k -= pq.top();
                ans--;
                pq.pop();
            } else break;
        }
        cout << ans << "\n";
    }
}

Answer: 2


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

void solve(){
    int n, k;
    cin>>n>>k;
    vector<int> v(n), f;
    map<int, int> m;
    for(int i = 0; i < n; i++){
        cin>>v[i];
        m[v[i]]++;
    }
    if(k >= n){
        cout<<1<<endl;
        return;
    }
    int ct = 0;
    for(auto it: m){
        if(it.second > k) ct++;
        else f.push_back(it.second);
    }
    sort(f.begin(), f.end());
    for(int j = 0; j < f.size(); j++){
        if(k >= f[j]) {
            k -= f[j];
        }
        else ct++;
    }
    cout<<ct<<"\n";
}

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

#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> v(n);
        set<int> s;
        int mini = INT_MAX, cm = INT_MAX;
        int p = 0;
        for(int i = 0; i < n; i++){
            int a;
            cin>>a;
            v[i] = a;
            if(k == 0){
                s.insert(a);
            }
            else if(k == 1){
                mini = min(mini, a);
                s.insert(mini);
            }
        }
        if(k > 1){
            for(int i = 0; i < n; i+=k){
                cm = v[i];
                for(int j = 1; j < k; j++){
                    if(j+i > n) break;
                    cm = min(cm, v[(j+i)]);
                }
                s.insert(cm);
            }
        }
        cout<<s.size()<<"\n";
    }
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long
#define MOD 1000000007

signed main() {
    fastio();
    int test;
    cin >> test;

    while (test--) {
        int n,m,k;
        cin >>n>>k;
        unordered_map<int,int>mp;
        int y=0,ans=0;

        vector<int> a(n),ele;
        for (int i = 0; i < n; i++) {
            cin>>a[i];
        }
        sort(a.begin(),a.end());
        int c=1;
        for (int i = 1; i < n; i++) {
            if(a[i]==a[i-1]){
                c++;
            }
            else{
                ele.push_back(c);
                c=1;
            }
        }
        ele.push_back(c);
        sort(ele.begin(),ele.end());
        int i=0;
        while(i<ele.size() && ele[i]<=k){
            // cout<<ele[i]<<" ";
            k-=ele[i];
            ele[i]=0;
            i++;
        }

        // for (int i = 0; i < n; i++) {
        //     cout<<a[i]<<" ";
        // }
        if(i==ele.size()) cout<<1<<endl;
        else
        cout<<ele.size()-i<<endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long
#define MOD 1000000007

signed main() {
    fastio();
    int test;
    cin >> test;

    while (test--) {
        int n,m,k;
        cin >>n>>k;
        unordered_map<int,int>mp;
        int y=0,ans=0;

        vector<int> a(n),ele;
        for (int i = 0; i < n; i++) {
            cin>>a[i];
        }
        sort(a.begin(),a.end());
        int c=1;
        for (int i = 1; i < n; i++) {
            if(a[i]==a[i-1]){
                c++;
            }
            else{
                ele.push_back(c);
                c=1;
            }
        }
        sort(ele.begin(),ele.end());
        int i=0;
        while(i<ele.size() && ele[i]<=k){
            // cout<<ele[i]<<" ";
            k-=ele[i];
            ele[i]=0;
            i++;
        }

        // for (int i = 0; i < n; i++) {
        //     cout<<a[i]<<" ";
        // }
        cout<<ele.size()-i+1<<endl;
    }

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin>>t;
	while(t--){
		long long n,m=0,j,count=1,k,x;cin>>n>>k;
		vector<long long>v(n),a(n);set<long long>s;
		for(long long i=0;i<n;i++){cin>>v[i];}sort(v.begin(),v.end());
        for(long long i=0;i<n-1;i++){
            if(v[i]==v[i+1]){count++;}
            else{count=1;}
            m=max(count,m);
        }
        //cout<<m<<endl;

        /*for(long long i=n-1;i>=0;i--){
            if(v[i]!=x){k--;}
            if(k==0){j=i;break;}
        }*/
        if(m>k||m==1){m=0;}
        for(long long i=0;i<n-k-m;i++){
            s.insert(v[i]);
        }if(n==k||n-k-m<=0){cout<<"1"<<endl;}else{
        cout<<s.size()<<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()-1;i++){if(k>=a[i]){k-=a[i];ans--;}}
        cout<<ans<<endl;
    }
}

Answer: 2


#include<iostream>
#include<map>
using namespace std;
int main(){
                    int t;
                    cin>>t;
                    unordered_map<int,int>mp;
                    while(t--){
                             int n,k;
                             cin>>n>>k;
                             int a[];
                             mp.clear();
                             for(int i=0; i<n; i++){
                                                 cin>>a[i];
                                                 mp[a[i]]++;
                             }
                             multiset<int>st;
                             for(auto b:mp){
                                                 st.push(b.second);
                             }
                             int ans = st.size();
                             for(auto a : st){
                                                 if(k>=a){
                                                                     ans--;
                                                                     m-=a;
                                                 }
                             }
                             cout<<ans<<endl;

                    }
                    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());

        int passes = vec.size();

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

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

int main(){

    solver();
;
}

Answer: 1


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

// 1,2,3,4,5,6,7,8
//1,4,9,16,25,36,49

#define NMAX (4*100005)

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

    int arr[n];
    fill(arr, arr+n, INT_MAX);
    int i = 0;
    for (auto [first, second] : mp) {
        // cout << second << " ";
        arr[i] = second;
        i++;
    }
    // cout << endl << " -> ";
    sort(arr, arr+n);
    for (int i = 0; i < n; i++) {
        if (arr[i] <= k) {
            k = k-arr[i];
        } else {
            cout << mp.size() - i << endl;
            return;
        }
    }
    cout << 1 << endl;

}

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

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

// 1,2,3,4,5,6,7,8
//1,4,9,16,25,36,49

#define NMAX (4*100005)

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

    int arr[n];
    fill(arr, arr+n, INT_MAX);
    int i = 0;
    for (auto [first, second] : mp) {
        // cout << second << " ";
        arr[i] = second;
        i++;
    }
    // cout << endl << " -> ";
    sort(arr, arr+n);
    for (int i = 0; i < n; i++) {
        if (arr[i] <= k) {
            k = k-arr[i];
        } else {
            if (mp.size() - i  == 0) cout << 1 << endl;
            else cout << mp.size() - i << endl;
            return;
        }
    }
    cout << 1 << endl;

}

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

Answer: 2


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

// Fast I/O
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

// Input/Output file setup for debugging
#ifndef ONLINE_JUDGE
    #define FILE_IO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);freopen("error.txt", "w", stderr)
#else
    #define FILE_IO
#endif

// Type Definitions
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define vii vector<int>
#define vll vector<ll>
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

// Constants
const ll MOD = 1e9 + 7;     // Modular arithmetic constant

// Debugging Macro (Prints variable values during local testing)
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << " = " << x << endl
    #define debugv(v) cerr << #v << " = "; for (auto i : v) cerr << i << " "; cerr << endl
#else
    #define debug(x)
    #define debugv(x)
#endif

// Utility Functions
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 modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }

// Main problem-solving function
void solve() {
    int n,k;
    cin >> n >> k;
    map<int,int> mp;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        mp[x]++;
    }

    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<>> pq;

    for(auto &a: mp){
        pq.push({a.ss,a.ff});
    }
    while(k > 0 && !pq.empty()){
        auto [f,s] = pq.top();
        pq.pop();
        if(k >= f){
            k -= f;
        }
        else{
            pq.push({f-k,s});
            k = 0;
        }
    }
    cout << max(1,(int)sz(pq)) << endl;

}

int main() {
    // File and Fast I/O Setup
    FAST_IO;
    FILE_IO;

    // Number of test cases
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

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

// Fast I/O
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

// Input/Output file setup for debugging
#ifndef ONLINE_JUDGE
    #define FILE_IO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);freopen("error.txt", "w", stderr)
#else
    #define FILE_IO
#endif

// Type Definitions
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define vii vector<int>
#define vll vector<ll>
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

// Constants
const ll MOD = 1e9 + 7;     // Modular arithmetic constant

// Debugging Macro (Prints variable values during local testing)
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << " = " << x << endl
    #define debugv(v) cerr << #v << " = "; for (auto i : v) cerr << i << " "; cerr << endl
#else
    #define debug(x)
    #define debugv(x)
#endif

// Utility Functions
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 modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }

// Main problem-solving function
void solve() {
    int n,k;
    cin >> n >> k;
    vii v(n);
    for(int &a: v) cin >> a;
    sort(all(v));
    set<int> st;
    for(int i = k; i < n; ++i){
        st.insert(v[i]);
    }
    cout << ((sz(st) > 0)? sz(st): 1) << endl;

}

int main() {
    // File and Fast I/O Setup
    FAST_IO;
    FILE_IO;

    // Number of test cases
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Answer: 1


#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define optimize() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
    optimize();
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int arr[n];
        map<int,int>mp;
        for(int i=0;i<n;i++)
        {
         cin>>arr[i];
         mp[arr[i]]++;
        }
        vector<int>v;
        for(auto u:mp)v.push_back(u.second);
         sort(v.begin(),v.end());
         int cnt=v.size();
        for(auto u:v)
        {
         if(u<=k)
          {
            cnt--;
            k=k-u;
          }
        }
        cout<<max(1,cnt)<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define endlb'\n'
#define ll long long
#define optimize() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
    optimize();
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int>arr(n);
        unordered_map<int,int>freq_map;
        for(int i=0;i<n;i++){
            cin>>arr[i];
            freq_map[arr[i]]++;
        }
        vector<pair<int,int>>freq_vec;
        for(auto&entry:freq_map){
            freq_vec.push_back(entry);
        }
        sort(freq_vec.begin(),freq_vec.end(),[](pair<int,int>&a,pair<int,int>&b){
            return a.second<b.second;
        });
        int cnt=0;
        for(auto&u:freq_vec){
            if(u.second<=k){
                k-=u.second;
                u.second=0;
            }
        }

        for(auto&u:freq_vec){
            if(u.second!=0)cnt++;
        }
        if(cnt==0)cout<<1<<endl;
        else cout<<cnt<<endl;
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int t;
    cin>>t;
    while(t--){
      int n, k;
      cin>>n>>k;
      vector<ll> vec;
      for(int i=0; i<n; i++){
        ll x;
        cin>>x;
        vec.push_back(x);
      }
      map<int, int> mp;
      for(int i=0; i<vec.size(); i++){
        mp[vec[i]]++;
      }
      vector<vector<int>> kv;
      for(auto i:mp){
        vector<int> ins(2);
        ins[0] = i.second;
        ins[1] = i.first;
        kv.push_back(ins);
      }
      sort(kv.begin(), kv.end());
      int i=0;
      while(k>0 && i<kv.size()){
        if(k>=kv[i][0]){
          k-=kv[i][0];
          i++;
        }
        else{
          break;
        }
      }
      if(i == kv.size()) cout<<1<<endl;
      else{
      cout<<kv.size()-i<<endl;
      }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int t;
    cin>>t;
    while(t--){
      int n, k;
      cin>>n>>k;
      vector<ll> vec;
      for(int i=0; i<n; i++){
        ll x;
        cin>>x;
        vec.push_back(x);
      }
      map<int, int> mp;
      for(int i=0; i<vec.size(); i++){
        mp[vec[i]]++;
      }
      vector<vector<int>> kv;
      for(auto i:mp){
        vector<int> ins(2);
        ins[0] = i.second;
        ins[1] = i.first;
        kv.push_back(ins);
      }
      sort(kv.begin(), kv.end());
      int i=0;
      while(k>0 && i<kv.size()){
        if(k>=kv[i][0]){
          k-=kv[i][0];
          i++;
        }
      }
      if(i == kv.size()) cout<<1<<endl;
      else{
      cout<<kv.size()-i<<endl;
      }
    }
    return 0;
}

Answer: 1


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#define int long long
using namespace std;
//  不需要将 大的数字 保存下来

signed main() {
    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 并按频率排序
        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 removed = 0;
        for (int d : cnt) {
            if (k >= d) {
                k -= d;
                removed++;
            }
            else {
                break; // 如果 k 不足以替换当前频率，直接退出
            }
        }

        // 计算答案
        int c = cnt.size() - removed;
        int ans = max(c , 1LL) ;
        cout << ans << endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include<queue>
#define int long long
using namespace std;

signed main() {
    int t; // 测试用例数量
    cin >> t;
    while (t--) {
        priority_queue<int, vector<int>, greater<int>>pq;
        int n, k; // 数组长度和最多替换次数
        cin >> n >> k;
        unordered_map<int, int> freq; // 统计频率
        vector<int> a(n);

        // 读取输入并统计频率
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            freq[a[i]]++;
        }

        // 将频率提取为 vector 并按频率排序
        vector<int> counts;
        for (auto& p : freq) {
            pq.push(p.second);
        }
        /*sort(counts.begin(), counts.end());*/

        // 计算可以移除的不同数字的数量
        int removed = 0;

        while (k > 0) {
            int l = pq.top();
            k -= l;
            pq.pop();
            if (k >= 0)removed++;
        }

        // 计算答案

        int ans = max((int)freq.size() - removed, 1LL);
        cout << ans << endl;
    }
    return 0;
}

Answer: 1


#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	// sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i])
			m-=num[i];
		else{
			printf("%lld\n",s-i);
			flag=true;
			break;
		}
	}
	if(!flag){
		printf("1\n");
	}
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i]){
			m-=num[i];
		}
		else{
			printf("%lld\n",s-i);
			flag=true;
			return;
		}
	}
	printf("1\n");
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Answer: 2


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

int assign_smallest_to_largest(vector<pair<int, int>> &lis, int k, int n){
    int i = 0;
    int current_most = lis.back().first;
    int cnt = 0;
    // cout << "current_most "<<current_most << "n:"<< n << endl;
    // for(int i = 0; i < lis.size(); i++){
    //     cout << "data before: "<<lis[i].first << " " << lis[i].second << endl;
    // }
    for (int i = 0; i < lis.size(); i++)
    {
        if(lis[i].first == current_most){
            continue;
        }
        if(lis[i].second <= k){
            lis.back().second += lis[i].second;
            k -= lis[i].second;
            lis[i].second = 0;
        }
        else{
            break;
        }
    }

    for(int i = 0; i < lis.size(); i++){
        // cout << "data: "<<lis[i].first << " " << lis[i].second << endl;
        if(lis[i].second > 0){
            cnt++;
        }
    }
    return cnt;
}

map<int, int> m;
vector<pair<int, int>> lis;
int main(){
    ios::sync_with_stdio(false); // 取消同步流
    cin.tie(0); // 解绑cin与cout
    cout.tie(0); // 解绑cout与cin
    int t, n, k;
    cin >> t;

    for(int i = 0; i < t; i++){
        cin >> n >> k;
        for(int j = 0; j < n; j++){
            int x;
            cin >> x;
            m[x]++;
        }
        // cout << "msize: "<<m.size() << endl;
        lis.clear();
        for (auto i = m.begin(); i != m.end(); i++)
        {
            lis.push_back(make_pair(i->first, i->second));
            //cout << "data pushed: "<<i->first << " " << i->second << endl;
        }
        // cout << "data size: "<<lis.size() << endl;

        sort(lis.begin(), lis.end(), [](const pair<int, int> &a, const pair<int, int> &b){
            return a.second < b.second;
        });

        cout << assign_smallest_to_largest(lis, k, n) << endl;
        // cout << "lis size" << lis.size() << endl;
        m.clear();
    }

    return 0;
}

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

int assign_smallest_to_largest(vector<pair<int, int>> &lis, int k, int n){
    int i = 0;
    int current_most = lis.back().first;
    int cnt = 0;
    // cout << "current_most "<<current_most << "n:"<< n << endl;
    // for(int i = 0; i < lis.size(); i++){
    //     cout << "data before: "<<lis[i].first << " " << lis[i].second << endl;
    // }
    for (int i = 0; i < lis.size(); i++)
    {
        if(lis[i].first == current_most){
            continue;
        }
        if(lis[i].second <= k){
            lis.back().second += lis[i].second;
            k -= lis[i].second;
            lis[i].second = 0;
        }
        else{
            break;
        }
    }

    for(int i = 0; i < lis.size(); i++){
        // cout << "data: "<<lis[i].first << " " << lis[i].second << endl;
        if(lis[i].second > 0){
            cnt++;
        }
    }
    return cnt;
}

unordered_map<int, int> m;
vector<pair<int, int>> lis;
int main(){
    ios::sync_with_stdio(false); // 取消同步流
    cin.tie(0); // 解绑cin与cout
    cout.tie(0); // 解绑cout与cin
    int t, n, k;
    cin >> t;

    for(int i = 0; i < t; i++){
        cin >> n >> k;
        for(int j = 0; j < n; j++){
            int x;
            cin >> x;
            m[x]++;
        }
        // cout << "msize: "<<m.size() << endl;
        lis.clear();
        for (auto i = m.begin(); i != m.end(); i++)
        {
            lis.push_back(make_pair(i->first, i->second));
            //cout << "data pushed: "<<i->first << " " << i->second << endl;
        }
        // cout << "data size: "<<lis.size() << endl;

        sort(lis.begin(), lis.end(), [](const pair<int, int> &a, const pair<int, int> &b){
            return a.second < b.second;
        });

        cout << assign_smallest_to_largest(lis, k, n) << endl;
        // cout << "lis size" << lis.size() << endl;
        m.clear();
    }

    return 0;
}

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 mxn = v[0];
        int cnt = 1;
        for(int i = 1; i < n; i++)
        {
            if(v[i] == v[i-1])
                cnt++;
            else
            {
                if(mx < cnt)
                {
                    mx = cnt;
                    cnt = 1;
                    mxn = v[i-1];
                }
            }
        }

        for(int i = 0; i < n && k > 0; i++)
        {
            if(v[i] != mxn)
            {
                v[i] = mxn;
                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>
#define int long long
using namespace std;
unordered_map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	idt=0;
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	int ans=num.size();
	for(auto i:num){
		if(m<=0)break;
		if(i<=m){
			m-=i;
		}
		ans--;
	}
	printf("%lld\n",max(ans,1ll));
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Answer: 1


#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rev(i, a, b) for (int i = a; i >= (b); i--)
#define fr first
#define sc second
#define pb push_back
#define endl "\n"

template<class T, class U> inline void chmin(T& a, U b) { if (a > b) a = b; }
template<class T, class U> inline void chmax(T& a, U b) { if (a < b) a = b; }

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//void reset() {}

void solve_task() {
    int n,k;cin >> n >> k;
    vector<ll> a(n);
    map<ll,ll> cnt;

    rep(i,0,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    sort(all(a),[&](int x,int y) {
        if(cnt[x] == cnt[y]) return x < y;
        return cnt[x] < cnt[y];
    });

    rep(i,0,k) a[i] = a[n - 1];

    sort(all(a));
    int ans = 1;
    rep(i,1,n) ans += (a[i] != a[i - 1]);
    cout << ans << endl;
}

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

    int tc = 1;cin >> tc;
    while(tc--) solve_task();

    return 0;
}

#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rev(i, a, b) for (int i = a; i >= (b); i--)
#define fr first
#define sc second
#define pb push_back
#define endl "\n"

template<class T, class U> inline void chmin(T& a, U b) { if (a > b) a = b; }
template<class T, class U> inline void chmax(T& a, U b) { if (a < b) a = b; }

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//void reset() {}

void solve_task() {
    int n,k;cin >> n >> k;
    vector<ll> a(n);
    map<ll,ll> cnt;

    rep(i,0,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    sort(all(a),[&](int x,int y) {
        return cnt[x] <= cnt[y];
    });

    rep(i,0,k) {
        cnt[a[i]]--;
        a[i] = a[n - 1];
        cnt[a[i]]++;
    }

    sort(all(a));
    int ans = 1;
    rep(i,1,n) ans += (a[i] != a[i - 1]);
    cout << ans << endl;
}

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

    int tc = 1;cin >> tc;
    while(tc--) solve_task();

    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    vector<int> nums(n);
    for (int &i: nums) {
      cin >> i;
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    sort(nums.begin(), nums.end());
    vector<int> cnt{1};
    int ans = 0;
    for (int i = 1; i < n; ++i) {
      if (nums[i] == nums[i - 1]) {
	++cnt.back();
      } else {
	cnt.emplace_back(1);
      }
    }
    sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    for (int i = 0; i < m - 1; ++i) {
      if (cnt[i] > k) {
	ans = m - i;
	break;
      }
      k -= cnt[i];
    }
    cout << max(ans, 1) << endl;
  }
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data;
    for (auto &[k, v]: nums) {
      data.push_back({v, k});
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}

Answer: 1


#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

/*
stole from editorial, my intuition was correct about it being
"base state of ans is the num of unique elements, to get minimum value of f(a) we reduce
the number of unique elements", just that my implementation was incorrect.
*/

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

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

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::sort(all(v));
        std::vector<int> cnt = {1};
        for (int i = 1; i < n; i++)
        {
            if (v[i] == v[i - 1])
                cnt.back()++;
            else
                cnt.emplace_back(1);
        }
        std::sort(all(cnt));
        int m = cnt.size(); bool chk{false};
        for (int i = 0; i < m - 1; i++)
        {
            if (cnt[i] > k)
            {
                std::cout << m - i << "\n";
                chk = true;
                break;
            }
            k -= cnt[i];
        }
        if(!chk)
           std::cout << 1 << "\n";
    }
}

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

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

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

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::map<int, int> cnt{};
        for (int num : v)
           cnt[num]++;

        int ans = std::set(all(v)).size();
        std::vector<std::pair<int, int>> pairs(cnt.begin(), cnt.end());
        std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b)
        {
            return a.second < b.second;
        });

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

        if(ans == 0)
            std::cout << 1 << '\n';
        else
            std::cout << ans << '\n';
    }
}

Answer: 1


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

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

  auto __solve=[&](int test){
    int n,k;
    cin>>n>>k;
    map<int,int> mp;
    for(int i=0;i<n;i++){
      int x;
      cin>>x;
      mp[x]++;
    }
    int size=mp.size();
    if(k>=n){
      cout<<1<<'\n';
      return;
    }
    vector<int> v(size);
    int ind=0,cnt=0;
    for(auto it:mp){
      v[ind]=it.second;
      ind++;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<size;i++){
      if(k>=v[i]){
        k-=v[i];
        cnt++;
      }
      else{
        break;
      }
    }

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

  int t=1;
  cin>>t;
  while(t--){
    __solve(t);
  }
    return 0;
}

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

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

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

    if(k>=n){
      cout<<1<<'\n';
      return;
    }
    int ans=0;
    for(auto &it:mp){
      ans+=(it.second+1)/2;
    }

    ans-=k;
    cout<<ans<<'\n';
  };

  int t=1;
  cin>>t;
  while(t--){
    __solve(t);
  }
    return 0;
}

Answer: 2


#include <iostream>				// Hello 2025 B
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#define ll long long
using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		mp[num]++;
	}
	for (auto i : mp) {
		a.push_back(i.second);
	}
	sort(a.begin(), a.end());
	int ans = a.size();
	int l = 0, r = a.size() - 1;
	while (k > 0 && l < r) {
		if (a[l] <= a[r]) {
			k -= a[l];
			l++, ans--;
		}
		else {
			k -= a[r];
			r--, ans--;
		}
	}
	if (k < 0) ans++;
	cout << ans << endl;
}

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

	return 0;
}

#include <iostream>				// Hello 2025 B
#include <vector>
#include <map>
#include <math.h>
#define ll long long
using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		mp[num]++;
	}
	for (auto i : mp) {
		a.push_back(i.second);
	}
	int ans = a.size();
	int l = 0, r = a.size() - 1;
	while (k > 0 && l < r) {
		if (a[l] <= a[r]) {
			k -= a[l];
			l++, ans--;
		}
		else {
			k -= a[r];
			r--, ans--;
		}
	}
	if (k < 0) ans++;
	cout << ans << endl;
}

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

	return 0;
}

Answer: 1


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

int assign_smallest_to_largest(vector<pair<int, int>> &lis, int k){
    int i = 0;
    int current_most = lis.back().first;
    int cnt = 0;
    // cout << "current_most "<<current_most << endl;
    // for(int i = 0; i < lis.size()/2; i++){
    //     cout << "data before: "<<lis[i].first << " " << lis[i].second << endl;
    // }
    for (int i = 0; i < lis.size()/2; i++)
    {
        if(lis[i].first == current_most){
            continue;
        }
        if(lis[i].second <= k){
            lis.back().second += lis[i].second;
            k -= lis[i].second;
            lis[i].second = 0;
        }
        else{
            break;
        }
    }

    for(int i = 0; i < lis.size()/2; i++){
        // cout << "data: "<<lis[i].first << " " << lis[i].second << endl;
        if(lis[i].second > 0){
            cnt++;
        }
    }
    return cnt;
}

int main(){
    int t, n, k;
    cin >> t;
    unordered_map<int, int> m;
    for(int i = 0; i < t; i++){
        cin >> n >> k;
        for(int j = 0; j < n; j++){
            int x;
            cin >> x;
            m[x]++;
        }
        // cout << "msize: "<<m.size() << endl;
        vector<pair<int, int>> lis(m.begin(), m.end());
        for (auto i = m.begin(); i != m.end(); i++)
        {
            lis.push_back(make_pair(i->first, i->second));
            // cout << "data pushed: "<<i->first << " " << i->second << endl;
        }
        // cout << "data size: "<<lis.size() << endl;

        sort(lis.begin(), lis.end(), [](const pair<int, int> &a, const pair<int, int> &b){
            return a.second < b.second;
        });

        cout << assign_smallest_to_largest(lis, k) << endl;
        m.clear();
    }

    return 0;
}

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

int assign_smallest_to_largest(vector<pair<int, int>> &lis, int k, int n){
    int i = 0;
    int current_most = lis.back().first;
    int cnt = 0;
    // cout << "current_most "<<current_most << "n:"<< n << endl;
    // for(int i = 0; i < lis.size(); i++){
    //     cout << "data before: "<<lis[i].first << " " << lis[i].second << endl;
    // }
    for (int i = 0; i < lis.size(); i++)
    {
        if(lis[i].first == current_most){
            continue;
        }
        if(lis[i].second <= k){
            lis.back().second += lis[i].second;
            k -= lis[i].second;
            lis[i].second = 0;
        }
        else{
            break;
        }
    }

    for(int i = 0; i < lis.size(); i++){
        // cout << "data: "<<lis[i].first << " " << lis[i].second << endl;
        if(lis[i].second > 0){
            cnt++;
        }
    }
    return cnt;
}

map<int, int> m;
vector<pair<int, int>> lis;
int main(){
    ios::sync_with_stdio(false); // 取消同步流
    cin.tie(0); // 解绑cin与cout
    cout.tie(0); // 解绑cout与cin
    int t, n, k;
    cin >> t;

    for(int i = 0; i < t; i++){
        cin >> n >> k;
        for(int j = 0; j < n; j++){
            int x;
            cin >> x;
            m[x]++;
        }
        // cout << "msize: "<<m.size() << endl;
        lis.clear();
        for (auto i = m.begin(); i != m.end(); i++)
        {
            lis.push_back(make_pair(i->first, i->second));
            //cout << "data pushed: "<<i->first << " " << i->second << endl;
        }
        // cout << "data size: "<<lis.size() << endl;

        sort(lis.begin(), lis.end(), [](const pair<int, int> &a, const pair<int, int> &b){
            return a.second < b.second;
        });

        cout << assign_smallest_to_largest(lis, k, n) << endl;
        // cout << "lis size" << lis.size() << endl;
        m.clear();
    }

    return 0;
}

Answer: 2


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

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

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}

Answer: 2


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10,INF=0x3f3f3f3f,mod= 1e9 + 7;
/*int primes[N];bool st[N];int cnt=0;
void getpri(int n)
{
    for(int i=2;i<=n; i++)
    {
        if(!st[i]) primes[cnt++] = i;
        for(int j=0; primes[j] <= n/i; j++)
            {
            st[primes[j]*i]=true;
            if(i%primes[j]==0) break;
            }
    }
}*/
int qsm(int n,int m)/*n^m*/
{
    int res=1;
    while(m)
    {
        if(m&1)
        res=res*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return res;
}
map<int,int>mp,mpp;
void solve()
{
    mp.clear();
	int n,k;
    cin>>n>>k;
    if(n==k){cout<<1<<endl;return;}
    int cnt=0;
    int  a[N] = {0};
    vector<int>s;
    set<int>p;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(mp[a[i]]==0)cnt++,p.insert(a[i]);
        mp[a[i]]++;

    }//求种类数；

    for(auto l=p.begin();l!=p.end();l++)
    {
        s.push_back(mp[*l]);
    }//把元素个数取出来

    sort(s.begin(),s.end());//排序

    for(int i=0;i<s.size();i++)
    {
        if(k<s[i])break;
        if(k>=s[i])k-=s[i],cnt--;
    }
    cout<<cnt<<endl;
}
signed main()
{
	ios::sync_with_stdio(0); cin.tie(0),cout.tie(0);
  	int T=1;
  	cin>>T;
  	while(T--)
  	{
  		solve();
	}
    return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10,INF=0x3f3f3f3f,mod= 1e9 + 7;
/*int primes[N];bool st[N];int cnt=0;
void getpri(int n)
{
    for(int i=2;i<=n; i++)
    {
        if(!st[i]) primes[cnt++] = i;
        for(int j=0; primes[j] <= n/i; j++)
            {
            st[primes[j]*i]=true;
            if(i%primes[j]==0) break;
            }
    }
}*/
int qsm(int n,int m)/*n^m*/
{
    int res=1;
    while(m)
    {
        if(m&1)
        res=res*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return res;
}
map<int,int>mp,mpp;
void solve()
{
    mp.clear();
	int n,k;
    cin>>n>>k;
    int cnt=0;
    int  a[N] = {0};
    vector<int>p;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(mp[a[i]]==0)cnt++;
        mp[a[i]]++;

    }//求种类数；

    for(auto x:mp)
    {
        p.push_back(x.second);
    }//取出来种类数；

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

    for(int i=0;i<p.size();i++)
    {
        if(k>=p[i])k-=p[i],cnt--;
    }
    cout<<max((int)1,cnt)<<endl;
}
signed main()
{
	ios::sync_with_stdio(0); cin.tie(0),cout.tie(0);
  	int T=1;
  	cin>>T;
  	while(T--)
  	{
  		solve();
	}
    return 0;
}

Answer: 2


if __name__ == "__main__":
    tc = 0
    tc = int(input())
    lres = []
    for i in range(tc):
        nkRaw = input()
        n = int(nkRaw.split(" ")[0])
        k = int(nkRaw.split(" ")[1])
        minimum = 0
        maximum = 1
        arrayRaw = input()
        array = arrayRaw.split(" ")
        diccionario = {}
        for num in range(int(n)):
            if(array[num] not in diccionario):
                diccionario[array[num]] = 1
            else:
                diccionario[array[num]] += 1;
        if(k >= len(diccionario)):
            lres.append(1)
            break
        else:
            sorted(diccionario.values())
            lista_diccionario = diccionario.values()
            aux = 0
            for num in lista_diccionario:
                if(num <= k):
                    k -= num
                    aux += 1
            lres.append(len(lista_diccionario) - aux)
    for res in lres:
        print(res)

# end main

if __name__ == "__main__":
    tc = 0
    tc = int(input())
    lres = []
    for i in range(tc):
        nkRaw = input()
        n = int(nkRaw.split(" ")[0])
        k = int(nkRaw.split(" ")[1])
        minimum = 0
        maximum = 1
        arrayRaw = input()
        array = arrayRaw.split(" ")
        diccionario = {}
        for num in range(int(n)):
            if(array[num] not in diccionario):
                diccionario[array[num]] = 1
            else:
                diccionario[array[num]] += 1;
        if(k >= n):
            lres.append(1)
        else:
            lista_diccionario = sorted(diccionario.values())
            aux = 0
            for num in lista_diccionario:
                if(num <= k):
                    k -= num
                    aux += 1
                else:
                    break
            lres.append(len(lista_diccionario) - aux)
    for res in lres:
        print(res)
#end

Answer: 2


#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, k;
        cin >> n >> k;
        map<int, int> freq;

        // Count occurrences
        for (int i = 0; i < n; i++) {
            int temp;
            cin >> temp;
            freq[temp]++;
        }

        // Extract frequencies and sort them
        vector<int> counts;
        for (auto &[num, count] : freq) {
            counts.push_back(count);
        }
        sort(counts.begin(), counts.end());

        int ans = counts.size();
        int i = 0;

        // Greedily remove smallest frequency elements
        while (i < counts.size() && k >= counts[i]) {
            k -= counts[i];
            ans--;
            i++;
        }

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

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

int main() {
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int ans=0;
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            int temp;
            cin>>temp;
            m[temp]+=1;
        }
        vector<int> v;
        for(auto i:m){
            v.push_back(i.second);
        }
        sort(v.begin(),v.end());
        ans=v.size();
        for(auto i:v){
            cout<<i<<",";
        }
        cout<<"\n";
        int h=0;
        while(k){
            if(v[h]<=k){
                k-=v[h];
                ans-=1;
            }
            else k=0;
            h+=1;
        }
        if(ans<=0) cout<<"1"<<"\n";
        else cout<<ans<<"\n";
    }
    return 0;
}

Answer: 1


#include <bits/stdc++.h>

using namespace std;

int f(vector<int>& b) {
    int n = b.size();
    if (n == 0) return 0;

    vector<int> dp(n + 1, INT_MAX);
    dp[0] = 0;

    for (int i = 1; i <= n; ++i) {
        int min_val = INT_MAX;
        for (int j = i; j > 0; --j) {
            min_val = min(min_val, b[j - 1]);
            dp[i] = min(dp[i], dp[j - 1] + 1);
        }
    }

    return dp[n];
}

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) {
         int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> a;
    for (int j = 0; j < n; ++j) {
        int x;
        cin >> x;
        a.push_back(x);
    }

    // Example usage of f(b)
    cout << f(a) << endl;}

    return 0;
}

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

void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        map<int, int> freq;

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

        if (n == k) {
            // If n == k, we can include all elements
            cout << 1 << endl;
            continue;
        }

        vector<int> counts;
        for (const auto& pair : freq) {
            counts.push_back(pair.second);
        }

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

        int removable = 0;
        int total = 0;
        for (int count : counts) {
            if (total + count <= k) {
                total += count;
                removable++;
            } else {
                break;
            }
        }

        int result = freq.size() - removable;
        cout << result << endl;
    }
}

int main() {
    solve();
    return 0;
}

Answer: 2


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

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

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

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

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

Answer: 2


#include<bits/stdc++.h>

using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;

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

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

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

    vector<pair<int, int> > freq(freqMap.begin(), freqMap.end());
    sort(freq.begin(), freq.end(), [](const auto &left, const auto &right) {
        return left.second < right.second;
    });

    int ans = freq.size();
    for (const auto &[_, count]: freq) {
        if (k == 0) break;
        if (count <= k) {
            k -= count;
            --ans;
        }
    }

    if (ans == 0) ++ans;

    cout << ans << "\n";
}

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

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

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;

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

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

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

    vector<pair<int, int> > freq(freqMap.begin(), freqMap.end());
    sort(freq.begin(), freq.end(), [](const auto &left, const auto &right) {
        return left.second < right.second;
    });

    int ans = freq.size();
    for (const auto &[_, count]: freq) {
        if (k == 0) break;
        if (count <= k) {
            k -= count;
            --ans;
        }
    }

    if (ans == 0) ++ans;

    cout << ans << "\n";
}

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

    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;
       int temp ;
       map<int,int>mp;
       for(int i= 0 ; i<n ; i++)
       {
           cin>>temp;
           mp[temp]++;
       }

       vector<int>v;
       for(auto it : mp)
       v.push_back(it.second);
       sort(v.begin(),v.end());
       int ans = v.size();

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

           ans--;

       }
       cout<<max(ans,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;
       int temp ;
       map<int,int>mp;
       for(int i= 0 ; i<n ; i++)
       {
           cin>>temp;
           mp[temp]++;
       }

       vector<int>v;
       for(auto &it : mp)
       v.push_back(it.second);
       sort(begin(v),end(v));
       int ans = v.size();

       for(int i = 0 ; i<n ; i++)
       {
           k-=v[i];
           if(k<=0)
           break;

           ans--;

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

    }

}

Answer: 1


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

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int c; cin >> c;
    while(c--){
        int n, k;
        cin >> n >> k;
        vector<int> arr;
        for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);}
        // put into groups that can be removed together
        // minimize groups
        // groups are contigous seperated by lower numbers
        // for each number store group (what information about the group. indexes? l and r of range. )
        // we need to store the amount of members of each group, and an arr of the locations (and thus the range)
        vector<int> numArr;
        unordered_map<int, int> numNums;
        for (int i : arr){
            if (numNums.count(i)) {
                (numNums[i] += 1);
            } else {
                numNums[i] = 1;
                numArr.push_back(i);

            }
        }
        vector<int> amtNums;
        for (int i : numArr){amtNums.push_back(numNums[i]);}
        sort(amtNums.begin(), amtNums.end());
        int groupsRmed = 0;
        for (int i : amtNums){
            k -= i;
            if (k < 0){
                break;
            } else {
                groupsRmed++;

            }
        }
        int res = (size(numArr) - groupsRmed != 0) ? (size(numArr) - groupsRmed) : 1;
        cout << res << "\n";

    }
}

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

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int c; cin >> c;
    while(c--){
        int n, k;
        cin >> n >> k;
        vector<int> arr;
        for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);}

        sort(arr.begin(), arr.end());
        // apearances, num
        vector<pair<int, int>> numUnique;
        int currApperances = 0;
        int last = arr[0];
        for (int i : arr){
            if (i == last){
                currApperances++;
            } else {
                numUnique.emplace_back(currApperances, last);
                currApperances = 1;
                last = i;
            }
        }
        numUnique.emplace_back(currApperances, last);

        sort(numUnique.begin(), numUnique.end());
        int removals = 0;
        for (pair<int, int> i : numUnique){
            k -= i.first;
            if (k < 0){
                break;
            }
            else{
                removals++;
            }
        }
        int res = (size(numUnique) - removals != 0) ? size(numUnique) - removals : 1;
        cout << res << "\n";

    }
}

Answer: 2


#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int>a,pair<int,int>b){
    if(a.second<b.second) return true;
    return false;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int l[n];
        vector<pair<int,int>>m;
        for(int i=0;i<n;i++){
            cin>>l[i];
        }
        sort(l,l+n);
        int say=1;
        for(int i=1;i<=n;i++){
            if(l[i]==l[i-1]){
                say++;
            }
            else{
                m.push_back({l[i-1],say});
                say=1;
            }

        }

        sort(m.begin(),m.end(),comp);
        for(auto& p:m){
            if(k==0){
                break;
            }
            if(k>=p.second){
                k-=p.second;
                p.second=0;

            }
            else{
                p.second-=k;
                k=0;
                break;
            }
        }
        int cvb=0;
        for(pair<int,int>p:m){
           // cout<<p.first<<" "<<p.second<<endl;
            if(p.second!=0){
                cvb++;
            }

        }
        if(cvb==0) cvb=1;
        cout<<cvb<<endl;

    }
}

#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int>a,pair<int,int>b){
    if(a.second<b.second) return true;
    return false;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int l[n];
        vector<pair<int,int>>m;
        for(int i=0;i<n;i++){
            cin>>l[i];
        }
        sort(l,l+n);
        int say=1;
        for(int i=1;i<n;i++){
            if(l[i]==l[i-1]){
                say++;
            }
            else{
                m.push_back({l[i-1],say});
                say=1;
            }

        }
        m.push_back({l[n-1],say});

        sort(m.begin(),m.end(),comp);
        for(auto& p:m){
            if(k==0){
                break;
            }
            if(k>=p.second){
                k-=p.second;
                p.second=0;

            }
            else{
                p.second-=k;
                k=0;
                break;
            }
        }
        int cvb=0;
        for(pair<int,int>p:m){
           // cout<<p.first<<" "<<p.second<<endl;
            if(p.second!=0){
                cvb++;
            }

        }
        if(cvb==0) cvb=1;
        cout<<cvb<<endl;

    }
}

Answer: 2


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

Answer: 2


n = int(input())
for _ in range(n):
    m, k = map(int, input().split())
    arr = list(map(int, input().split()))
    arr.sort()
    freqencies = list()
    count = 0
    prev = arr[0]
    for i in arr:
        if i == prev:
            count+=1
        else:
            prev = i
            freqencies.append(count)
            count = 1
    freqencies.append(count)
    freqencies.sort(reverse=True)
    remove = 0
    # print(freqencies, k)
    while len(freqencies) > 1 and remove + freqencies[-1] <= k:
        remove += freqencies.pop()
    print(len(freqencies))

n = int(input())
for _ in range(n):
    m, k = map(int, input().split())
    arr = list(map(int, input().split()))
    from collections import Counter
    freqencies = sorted(Counter(arr).values(), reverse=True)
    remove = 0
    # print(freqencies, k)
    while len(freqencies) > 1 and remove + freqencies[-1] <= k:
        remove += freqencies.pop()
    print(len(freqencies))

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];
    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];
    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){
            res--;
            e1++;
            k-=counts[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: 1


#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int>a(n);
        map<int,int>mapping;
        for(int i=0;i<n;i++){
            cin>>a[i];
            mapping[a[i]]++;
        }
        vector<int>freq;
        for(auto i:mapping){
            freq.push_back(i.second);
        }

        sort(freq.begin(),freq.end());
        for(int i=0;i<n;i++){
            if(freq[i]<=k){
              k=k-freq[i];
              freq[i]=0;
            }else{
                freq[i]=freq[i]-k;
                k=0;
                break;
            }
        }
        int count=0;
        for(auto i:freq){
            if(i!=0){
                count++;
            }
        }
        if(count==0){
            count=count+1;
        }
       cout<<count<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        map<int,int>mapping;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            mapping[x]++;
        }
        int maxi=INT_MIN;
        int key=-1;
        for(auto i:mapping){
         if(i.second>maxi){
            maxi=i.second;
            key=i.first;
         }
        }
        int count=0;
        for(auto &i:mapping){
         if(i.first!=key&&i.second<=k){
            int x=i.second;
            i.second=0;
            k=k-x;
            mapping[key]+=x;

         }else if(i.first!=key&&i.second>k){
            mapping[key]+=k;
            i.second=i.second-k;
            k=0;
         }
         if(k==0){
            break;
         }
        }
        for(auto i:mapping){
            if(i.second!=0){
                count++;
            }
        }
       cout<<count<<endl;
    }
}

Answer: 1


#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;
        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;
using ll=long long;
int d[1000001];
int maks=1000001;
int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
    ll n,k;
    cin>>n>>k;
    ll a[n];
    vector<int>v;
    for(ll i=0;i<n;i++)
    {
      cin>>a[i];
    }
    sort(a,a+n);
    ll say=1;
    for(ll i=0;i<n-1;i++)
    {
      if(a[i]==a[i+1])
      say++;
      else
      {
        v.push_back(say);
        say=1;
      }
  }
  v.push_back(say);
  sort(v.begin(),v.end());
  ll i=0,j=n-1;
  while(i<j and k!=0)
  {
    if( v[i]!=0)
    {
      v[i]=v[i]-1;
      k--;
    }
    if(v[i]==0)
    i++;
  }
  ll sa=0;
  for(ll g=0;g<v.size();g++)
  {
    if(v[g]>=1)
    sa++;
  }
  cout<<sa<<endl;
}
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int d[1000001];
int maks=1000001;
int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
    ll n,k;
    cin>>n>>k;
    ll a[n];
    vector<int>v;
    for(ll i=0;i<n;i++)
    {
      cin>>a[i];
    }
    sort(a,a+n);
    ll say=1;
    for(ll i=0;i<n-1;i++)
    {
      if(a[i]==a[i+1])
      say++;
      else
      {
        v.push_back(say);
        say=1;
      }
  }
  v.push_back(say);
  sort(v.begin(),v.end());
  ll i=0,j=n-1;
  while(i<j and k!=0)
  {
    if( v[i]!=0)
    {
      v[i]=v[i]-1;
      k--;
    }
    if(v[i]==0)
    i++;
  }
  ll sa=0;
  for(ll g=0;g<v.size();g++)
  {
    if(v[g]>=1)
    sa++;
  }
  if(sa!=0)
  cout<<sa<<endl;
  else
  cout<<1<<endl;
}
}

Answer: 2