Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 436 ms):
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;
ll n, k;
const int Max = 1e5 + 10;
ll a[Max];
struct node
{
	ll num;
	int index;
};
bool cmp(node aa, node ab)
{
	if (aa.num == ab.num)
	{
		return aa.index < ab.index;
	}
	return aa.num < ab.num;
}

ll cs[Max];

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> k;
		vector<node> b(n);

		for (int i = 0; i < n; i++)
		{
			//cin >> a[i];
			cin >> b[i].num;
			b[i].index = i;
		}
		if (k >= n)
		{
			cout << "1" << endl;
		}
		else
		{
			memset(a, 0, sizeof(a));
			sort(b.begin(), b.end(), cmp);
			int cnt = 0;
			for (int i = 0; i < n; i++)
			{
				if (i == 0 || (i!=0&&b[i].num != b[i - 1].num))
				{
					a[b[i].index] = ++cnt;
				}
				if (i!=0&&b[i].num == b[i - 1].num) a[b[i].index] = cnt;
			}
			memset(cs, 0, sizeof(cs));
			for (int i = 0; i < n; i++)
			{
				cs[a[i]]++;
			}
			sort(cs, cs + cnt + 1);
			int j = k;
			for (int i = 0; j > 0; i++)
			{
				if (j >= cs[i]) j -= cs[i], cs[i] = 0;
				else
				{
					j = 0;
					break;
				}
			}
			int ccnt = 0;
			for (int i = 0; i < cnt + 1; i++)
			{
				if (cs[i] != 0) ccnt++;
			}
			cout << ccnt << endl;
		}
	}
	return 0;
}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
#define ll long long
//-----------------------------------------------------------------------------------------------------------------------------------------------
#define array            \
    ll n;               \
    cin >> n;            \
    vector<ll> arr(n);   \
    for (auto &it : arr) \
    {                    \
        cin >> it;       \
    }
#define array2           \
    ll n;               \
    cin >> n;            \
    ll x;               \
    cin >> x;            \
    vector<ll> arr(n);   \
    for (auto &it : arr) \
    {                    \
        cin >> it;       \
    }
#define array3           \
    ll n;               \
    cin >> n;            \
    ll x;               \
    cin >> x;            \
    vector<ll> arr1(n);   \
    for (auto &it : arr1) \
    {                    \
        cin >> it;       \
    }                      \
    vector<ll> arr2(x);   \
    for (auto &it : arr2) \
    {                    \
        cin >> it;       \
    }
#define strr1   \
    string s; \
    cin >> s;
#define number \
    ll n;      \
    cin >> n;
//-----------------------------------------------------------------------------------------------------------------------------------------------
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define fb(i, n, m) for (ll i = (n); i >= (m); i--)
#define el endl
 
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define minus cout << "-1\n";
#define INF 1000000000
#define mod 1000000007
#define PI 3.141592653589793238462
 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define pr pair<ll,ll>
#define vl vector<ll>
#define vpr vector<pr>
 
#define sz(x) ((int)x.size())
//------------------------------------------------------------------------------------------------------------------------------------------------
void solve() {
    
    int n,m,k,a3,a4,a5,cnt=0;

    cin>>n>>k;
    vector<int> order,chk,chk2;
    map<int,int> mp1,mp2;

    // Read the elements into the chk vector
    for (int i = 0; i < n; i++) {
        cin >> a3;
        mp1[a3]++;
        chk.push_back(a3);
    }

    ll ans = mp1.size();

    for(auto itr:mp1){
        mp2[itr.second]++;
    }

    for(auto itr:mp2){
        // if(k==0){
        //     break;
        // }
        // int avele = itr.second*itr.first;
        // int p = min(avele,k);
        // int elemrem = p/itr.first;
        // ans -= elemrem;
        // k = k-elemrem;
        int avb = k/itr.first;
        int rem = min(avb,itr.second);
        ans = ans - rem;
        k = k - (rem*itr.first);

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





}
 
int main() {
    fast_cin();
    ll t = 1;
    cin >> t;
    for(int it=1;it<=t;it++){
        solve();
    }
    return 0;
}