Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
/*ॐ देविकानन्दनाय विधमहे वासुदेवाय धीमहि तन्नो कृष्ण:प्रचोदयात
ऊं श्रीं नमः श्रीकृष्णाय परिपूर्णतमाय स्वाहा
ओम क्लीम कृष्णाय नमः
श्री कृष्ण गोविंद हरे मुरारे, हे नाथ नारायण वासुदेवा
गोकुल नाथाय नमः
:निखिलेश गुप्ता*/


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

typedef long long ll;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(a, x) for (auto &a : x)
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    unordered_map<int, int> mp;
    for(int i = 0; i < n; i++){
        mp[arr[i]]++;
    }
    vector<int> freq;
    for(auto &x : mp){
        freq.push_back(x.second);
    }
    sort(begin(freq), end(freq), greater<int>());
    int i = freq.size() - 1;
    while(k > 0 && i >= 0){
        if(k >= freq[i]){
            k -= freq.back();
            freq.pop_back();
        }
        else break;
    }
    cout << (freq.empty() ? 1 : freq.size()) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int tt;
    cin >> tt;
    while(tt--) {
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
/*ॐ देविकानन्दनाय विधमहे वासुदेवाय धीमहि तन्नो कृष्ण:प्रचोदयात
ऊं श्रीं नमः श्रीकृष्णाय परिपूर्णतमाय स्वाहा
ओम क्लीम कृष्णाय नमः
श्री कृष्ण गोविंद हरे मुरारे, हे नाथ नारायण वासुदेवा
गोकुल नाथाय नमः
:निखिलेश गुप्ता*/


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

typedef long long ll;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(a, x) for (auto &a : x)
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    unordered_map<int, int> mp;
    for(int i = 0; i < n; i++){
        mp[arr[i]]++;
    }
    vector<int> freq;
    for(auto &x : mp){
        freq.push_back(x.second);
    }
    sort(begin(freq), end(freq), greater<int>());
    while(k > 0){
        if(k >= freq.back()){
            k -= freq.back();
            freq.pop_back();
        }
        else break;
    }
    cout << (freq.empty() ? 1 : freq.size()) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int tt;
    cin >> tt;
    while(tt--) {
        solve();
    }
    return 0;
}