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

Solution 1 (runtime: 140 ms):
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction(a) cout.unsetf(ios::floatfield);cout.precision(a);cout.setf(ios::fixed,ios::floatfield);
#define ll long long
#define endl '\n'
#define gap " "
#define bug(a) cerr<< #a << " : " << a <<endl
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define tc ll t; cin>>t; while(t--)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a*b)/(__gcd(a,b)))
const ll mod = 1000000007;
const double pi= acos(-1);
const int n=2*(1e5+10);
int main()
{
    optimize()
    tc
    {
        ll n,k;
        cin>>n>>k;
        vector<ll>v(n),v1;
        ll i;
        map<ll,ll>cnt;
        for(i=0;i<n;i++){
            cin>>v[i];
            cnt[v[i]]++;
        }
        ll n1=cnt.size();
        //bug(n1);
        ll c1=0;
        for(auto u:cnt){
           v1.pb(u.second);
        }
        sort(all(v1));
        for(i=0;i<n1;i++){
            if(v1[i]<=k){
                k-=v1[i];
                c1++;
            }
            else break;
        }
        if(c1==n1)cout<<1<<endl;
        else
        {
            cout<<n1-c1<<endl;
        }
    }
}

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

using namespace std;

int nproblems;
int n;
int k;
int tmp;
int minkey;
map<int, int> mp;
map<int, int>::iterator it = mp.begin();
int get_minkey();

int main(){
        cin >> nproblems;
        for(int i = 0; i< nproblems; i++){
                cin >> n;
                cin >> k;
                for(int j = 0; j <n; j++){
                        cin >> tmp; //current element of array
                        if(mp.count(tmp)){ //if key is allready in map
                                mp[tmp]++; //increment count
                        } else {
                                mp[tmp] = 1; //or add to map w/ count 1
                        }
                }
                if(mp.empty()){
                        mp = {};
                        cout << 0 << "\n";
                        continue;
                }

                //find number with maximum occurences
                int maxkey;
                it = mp.begin();
                maxkey = it -> first;
                it++;
                while(it != mp.end()){
                        if(it -> second >= mp[maxkey]){ //chose last max so that we dont collide w. min
                                maxkey = it -> first;
                        }
                        it++;
                }
                // remove k least frequent numbers
                if(mp.size() > 1){
                        while (k > 0){
                                //find least frequent number:
                                minkey = get_minkey();
                                
                                //now we have the smallest number of occurances
                                if(mp[minkey] <= k){ //if we have enough changes {k}
                                        //change all of the least frequent # to the most frequent
                                        mp[maxkey] += mp[minkey];
                                        k = k-mp[minkey];
                                        mp.erase(minkey);
                                } else { //we have less changes than the least frequent num
                                        //so changes wont reduce the number of moves.
                                        k = 0;
                                }

                        }
                }
                //do actual count of operations (# of distinct nums in list)
                cout << mp.size()<< "\n";
                mp = {}; //clear map at end of each loop
        }

        return 0;
}

int get_minkey(){
        it = mp.begin();
        int mn;
        mn = it->first;
        it++;
        while(it != mp.end()){
                if(mp[mn] == 1){
                        return mn; //get out of the llop as soon as we get a single
                }
                if(it->second < mp[mn]){
                        mn = it->first;
                }
                it++;
        }

        return mn;
}