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

Solution 1 (runtime: 109 ms):
// --------------- Compiler Optimizations ---------------
// Enable all optimizations and loop unrolling
#include <unordered_map>
#pragma GCC optimize("O3,unroll-loops")
// Enable CPU-specific instructions for faster execution
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

// --------------- Standard Library ---------------
// Include all standard libraries in one header
#include <unordered_set>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#include <utility>
using namespace std;

// --------------- Type Aliases ---------------
using ll = long long;                // 64-bit integer (-9e18 to 9e18)
using ull = unsigned long long;      // Unsigned 64-bit (0 to 18e18)
using ld = long double;              // Extended precision floating point
using pl = pair<ll, ll>;            // Pair of long longs
using vi = vector<int>;             // Integer vector
using vl = vector<ll>;              // Long long vector
using vpl = vector<pl>;             // Vector of pairs
using vc = vector<char>;            // Character vector
using vvi = vector<vi>;             // 2D integer vector
using vvl = vector<vl>;             // 2D long long vector

// --------------- Macros ---------------
// Container operations
#define all(x) begin(x), end(x)      // Entire range: v.begin(), v.end()
#define rall(x) rbegin(x), rend(x)   // Reverse range
#define sz(x) (int)(x).size()        // Container size
// Common operations
#define pb push_back                  // Vector push_back
#define mp make_pair                  // Create pair
#define F first                       // Pair first element
#define S second                      // Pair second element

// --------------- Constants ---------------
const ll INF = 2e18;             // Long long infinity
const int inf = 2e9;             // Int infinity
const ll MOD = 998244353;        // Common modulo in CP
const ld PI = 3.141592653589793238462;  // Pi value

// --------------- Fast I/O ---------------
// Fast integer input - faster than cin
template <typename T> void read(T& x) {
    bool neg = false;                 // Sign flag
    char c;                          // Current character
    x = 0;                           // Reset value
    c = getchar();                   // Read first char
    if (c == '-') {                  // Handle negative numbers
        neg = true;
        c = getchar();
    }
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + (c - '0');      // Build number
    if (neg) x = -x;                 // Apply sign
}

// Read multiple integers
template <typename T, typename... Args>
void read(T& x, Args&... args) {
    read(x);                         // Read first argument
    read(args...);                   // Read rest recursively
}

// --------------- Number Theory ---------------
// Greatest Common Divisor using Euclidean algorithm
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// Least Common Multiple using GCD
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// Binary Exponentiation with modulo
ll binpow(ll a, ll b, ll m = MOD) {
    ll res = 1;                      // Initialize result
    while (b > 0) {                  // While power > 0
        if (b & 1)                   // If current bit is 1
            res = res * a % m;       // Multiply result
        a = a * a % m;               // Square base
        b >>= 1;                     // Next bit
    }
    return res;
}

// Modular Multiplicative Inverse using Fermat's Little Theorem
ll modinv(ll x, ll m = MOD) { return binpow(x, m - 2, m); }

// --------------- Combinatorics ---------------
struct Combo {
    vl fact, invf;                   // Factorials and inverse factorials
    
    // Precompute factorials and inverses
    Combo(int n): fact(n + 1), invf(n + 1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) 
            fact[i] = fact[i-1] * i % MOD;
        // Compute inverse factorial using modinv
        invf[n] = modinv(fact[n]);
        for (int i = n; i; i--) 
            invf[i-1] = invf[i] * i % MOD;
    }
    
    // Calculate nCk modulo MOD
    ll C(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * invf[k] % MOD * invf[n-k] % MOD;
    }
};

// --------------- Graph Template ---------------
struct Graph {
    int n;                           // Number of vertices
    vector<vi> adj;                  // Adjacency list
    vi vis, dist;                    // Visited and distance arrays
    
    // Initialize graph with n vertices
    Graph(int _n): n(_n), adj(n), vis(n), dist(n) {}
    
    // Add undirected edge
    void add_edge(int u, int v) {
        adj[u].pb(v);
        adj[v].pb(u);
    }
    
    // BFS from starting vertex
    void bfs(int start) {
        fill(all(vis), 0);           // Reset visited array
        fill(all(dist), inf);        // Reset distances
        queue<int> q;                // BFS queue
        
        q.push(start);               // Add start vertex
        vis[start] = 1;              // Mark as visited
        dist[start] = 0;             // Distance to self = 0
        
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for (int u : adj[v]) {
                if (!vis[u]) {
                    vis[u] = 1;
                    dist[u] = dist[v] + 1;
                    q.push(u);
                }
            }
        }
    }
};

// --------------- Solution ---------------
void solve() {
    static map<int, int> freq;  // Static to avoid reallocation
    freq.clear();  // Clear previous test case data
    
    int n, k;
    scanf("%d %d", &n, &k);  // Faster I/O
    
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        freq[a]++;
    }
 
    vector<int> counts;
    counts.reserve(freq.size());  // Prevent reallocation
    for (const auto& [num, count] : freq) {
        counts.push_back(count);
    }
    sort(counts.begin(), counts.end());
 
    int remaining = counts.size();
    for (int f : counts) {
        if (k >= f) {
            k -= f;
            remaining--;
        } else break;
    }
    printf("%d\n", max(remaining, 1));  // Faster I/O
}


// --------------- Main ---------------
int main() {
    cin.tie(0)->sync_with_stdio(0);  // Untie cin from cout and disable sync
    
    int t = 1;                       // Number of test cases
    read(t);
    while (t--) solve();             // Process each test case
    
    return 0;
}


Solution 2 (runtime: 124 ms):
//Hara Hara Mahadev
#include<bits/stdc++.h>
using namespace std;
 
#define int 	long long
#define pi      3.1415926535897932384626433832795028841971693993751058
#define YES     cout<<"YES"<<"\n"
#define NO      cout<<"NO"<<"\n"
#define m1      cout<<-1<<"\n"
#define ssort(S)  sort((S).begin(),(S).end())
#define srev(S)   reverse((S).begin(),(S).end())
#define ll      long long
#define pb      push_back
#define vi      vector<int>
#define vvi 	vector<vector<int>>
#define vll      vector<long long>
#define vc      vector<char>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int>>
#define vs	 vector<string>
#define all(arr)  (arr).begin(), (arr).end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define inp(v) for (auto & a : (v)) cin >> a;
#define endl "\n"
#define speed (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define mod 1000000007
 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  

int ceil_div(int a, int b) {
   return a / b + ((a ^ b) > 0 && a % b != 0);
}

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


   map<int,int> mpp;
   for0(i, n) {
        int x; cin >> x; mpp[x]++;
   }

  vi arr;
   for(auto [ele, f]: mpp)
        arr.pb(f);

    sort(all(arr));
    int sum = 0;
    int sz = arr.size();

    for(int i=0; i<sz; i++) {
        if(sum + arr[i] <= k)
            sum += arr[i];
        else {
            cout << max(1, sz-i) << endl;
            return;
        }

    }
    cout << "1" << endl;
}

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