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

Solution 1 (runtime: 124 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long


void input(vector<ll> &v, int n) {
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v.push_back(x);
    }
}

void output(vector<ll> &v) {
    for (int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}

ll sum(ll n){
    return (n*(n+1))/2;
}

void solve() {
int n,k;
cin>>n>>k;
vector<ll> v,uni;
input(v,n);
int count=0;
sort(v.begin(),v.end());
// output(v);

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


// for(auto i:s1){
//     uni.push_back(i);
// }
int x=uni.size();
// vector<ll> freq(x);
sort(uni.begin(),uni.end());
// int last_idx=0;
// for(int i=0;i<uni.size();i++){
//     for(int j=last_idx;j<n;j++){
//         if(uni[i]!=v[j]){
//             last_idx=j;
//             break;
            
//         }
//         freq[i]++;
        
//     }
// }
// int j=0;
// for(int i=last_idx;i<n;i++){
//     if(v[i]==v[j]){
//         freq[j]++;
//     }
//     else {
//         last_idx=i;
//         j++;
        
//     }
// }

map<ll,ll> freq;
for(int i=0;i<n;i++){
    freq[v[i]]++;
}

for(auto &pr : freq){
    uni.push_back(pr.second);
    // cout<<pr.first<<" "<<pr.second<<endl;
    
}
sort(uni.begin(),uni.end());


if(k>=n-1) cout<<1<<endl;
else{
    for(int i=0;i<uni.size();i++){
    if(k>=uni[i]){
        k-=uni[i];
        uni[i]=0;
    }
    else break;
}
reverse(uni.begin(),uni.end());
for(int i=0;i<uni.size();i++){
    if(uni[i]==0) break;
    count++;
}
cout<<count<<endl;
}


}






    


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

    int t;
    cin >> t;

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

    return 0;
}

Solution 2 (runtime: 140 ms):
// inevitable -->> expert


/*


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


*/


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

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


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

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



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

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

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

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

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

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

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

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

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

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

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

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

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

	return hash;
}

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

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

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

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

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

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

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

}

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

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

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

	int t = 1;

	cin >> t;

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

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