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

Solution 1 (runtime: 218 ms):
#include <bits/stdc++.h>

//pair
#define PII pair <int, int>
#define PIII pair <PII, int>

//vector
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

//other
#define gcd __gcd

using namespace std;
namespace lhz{
	using T = int;
	inline T read(){
		T res = 0, f = 1;
		char ch = getchar();
		if(ch == '-') f = -1, ch = getchar();
		while (ch >= '0' && ch <= '9')
			res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
		return res * f;
	}
	
	inline void write(T n){
		if (n < 0) putchar('-'), n *= -1;
		if (n > 9) write(n / 10);
		putchar(n % 10 + '0');
	}
}

using ll = long long;
using db = double;
const int inf = 0x3f3f3f3f;
const double eqs = 1e-4;
const int mod = 1e8, N = 5005;

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

bool eq (double a, const double b){
	return fabs(a - b) > eqs;
}

template <typename T>
void cmax (T &a, T b){
	a = (a > b ? a : b);
}

template <typename T>
void cmin (T &a, T b){
	a = (a < b ? a : b);
}

template <typename T>
void swap (T &a, T &b){
    a = a ^ b, b = a ^ b, a = a ^ b;
}

int qmi (int a, int n, int p){
	int res = 1;
	while (n){
		if(n & 1) res = res * a % p;
		a = a * a % p, n >>= 1;
	}
	return res;
}

int inv (int a, int p){
	return qmi(a, p - 2, p);
}

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

int re (int a){
    return (a ^ (-1)) + 1;
}

int sabs (int a){
    return (a ^ (a >> 31)) - (a >> 31);
}

// m: 数的种类
int n, k, mx, m, u;
map <int, int> mp;
void sovle (){
    mx = 0, mp.clear();
    cin >> n >> k;
    
    vector <int> a(n);
    for (auto &v: a){
        cin >> v;
        if ( ++ mp[v] > mx) mx = mp[v], u = v;
    }
    
    sort (a.begin (), a.end ());
    a.erase (unique (a.begin (), a.end ()), a.end ());
    sort (a.begin (), a.end (), [&](const int a, const int b){
        return mp[a] < mp[b];
    });
    
    int cnt = 1;
    for (auto v: a) if (v != u){
        if (k >= mp[v]) { // 可以全部替换
            k -= mp[v], mp[v] = 0;
        } else { // 次数不够啦
            cnt ++;
        }
    }
    cout << cnt << '\n';
}

signed main (){
	cin.tie(nullptr) -> sync_with_stdio(false);
	
	int T = 1;
	cin >> T;
	while(T -- ) sovle();
	return 0;
}

Solution 2 (runtime: 124 ms):
#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;
}