ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: c++20 

Code 1:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#define int long long
using namespace std;
//  不需要将 大的数字 保存下来

signed main() {
    int t; // 测试用例数量
    cin >> t;
    while (t--) {
        int n, k; // 数组长度和最多替换次数
        cin >> n >> k;

        vector<int> a(n);

        // 读取输入并统计频率
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        // 将频率提取为 vector 并按频率排序
        vector<int>cnt = {1};
        for (int i = 1; i < n; i++) {
            if (a[i] == a[i - 1]) {
                cnt.back()++;
            }
            else {
                cnt.emplace_back(1);
            }
        }
        sort(cnt.begin(), cnt.end());
        // 计算可以移除的不同数字的数量
        int removed = 0;
        for (int d : cnt) {
            if (k >= d) {
                k -= d;
                removed++;
            }
            else {
                break; // 如果 k 不足以替换当前频率，直接退出
            }
        }

        // 计算答案
        int c = cnt.size() - removed;
        int ans = max(c , 1LL) ;
        cout << ans << endl;
    }
    return 0;
}

Code 2:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include<queue>
#define int long long
using namespace std;

signed main() {
    int t; // 测试用例数量
    cin >> t;
    while (t--) {
        priority_queue<int, vector<int>, greater<int>>pq;
        int n, k; // 数组长度和最多替换次数
        cin >> n >> k;
        unordered_map<int, int> freq; // 统计频率
        vector<int> a(n);

        // 读取输入并统计频率
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            freq[a[i]]++;
        }

        // 将频率提取为 vector 并按频率排序
        vector<int> counts;
        for (auto& p : freq) {
            pq.push(p.second);
        }
        /*sort(counts.begin(), counts.end());*/

        // 计算可以移除的不同数字的数量
        int removed = 0;

        while (k > 0) {
            int l = pq.top();
            k -= l;
            pq.pop();
            if (k >= 0)removed++;
        }

        // 计算答案

        int ans = max((int)freq.size() - removed, 1LL);
        cout << ans << endl;
    }
    return 0;
}

Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: c++23 

Code 1:
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	// sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i])
			m-=num[i];
		else{
			printf("%lld\n",s-i);
			flag=true;
			break;
		}
	}
	if(!flag){
		printf("1\n");
	}
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Code 2:
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	// int ans=num.size();
	// for(auto i:num){
	// 	if(m<=0)break;
	// 	if(i<=m){	
	// 		m-=i;
	// 	}
	// 	ans--;
	// }
	// printf("%lld\n",max(ans,1ll));
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i]){
			m-=num[i];
		}
		else{
			printf("%lld\n",s-i);
			flag=true;
			return;
		}
	}
	printf("1\n");
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

Code 1:
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i]){
			m-=num[i];
		}
		else{
			printf("%lld\n",s-i);
			flag=true;
			return;
		}
	}
	printf("1\n");
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Code 2:
#include<bits/stdc++.h>
#define int long long
using namespace std;
unordered_map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	idt=0;
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	int ans=num.size();
	for(auto i:num){
		if(m<=0)break;
		if(i<=m){
			m-=i;
		}
		ans--;
	}
	printf("%lld\n",max(ans,1ll));
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

Code 1:
#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rev(i, a, b) for (int i = a; i >= (b); i--)
#define fr first
#define sc second
#define pb push_back
#define endl "\n"

template<class T, class U> inline void chmin(T& a, U b) { if (a > b) a = b; }
template<class T, class U> inline void chmax(T& a, U b) { if (a < b) a = b; }

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//void reset() {}

void solve_task() {
    int n,k;cin >> n >> k;
    vector<ll> a(n);
    map<ll,ll> cnt;

    rep(i,0,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    sort(all(a),[&](int x,int y) {
        if(cnt[x] == cnt[y]) return x < y;
        return cnt[x] < cnt[y];
    });

    rep(i,0,k) a[i] = a[n - 1];

    sort(all(a));
    int ans = 1;
    rep(i,1,n) ans += (a[i] != a[i - 1]);
    cout << ans << endl;
}

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

    int tc = 1;cin >> tc;
    while(tc--) solve_task();

    return 0;
}

Code 2:
#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rev(i, a, b) for (int i = a; i >= (b); i--)
#define fr first
#define sc second
#define pb push_back
#define endl "\n"

template<class T, class U> inline void chmin(T& a, U b) { if (a > b) a = b; }
template<class T, class U> inline void chmax(T& a, U b) { if (a < b) a = b; }

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//void reset() {}

void solve_task() {
    int n,k;cin >> n >> k;
    vector<ll> a(n);
    map<ll,ll> cnt;

    rep(i,0,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    sort(all(a),[&](int x,int y) {
        return cnt[x] <= cnt[y];
    });

    rep(i,0,k) {
        cnt[a[i]]--;
        a[i] = a[n - 1];
        cnt[a[i]]++;
    }

    sort(all(a));
    int ans = 1;
    rep(i,1,n) ans += (a[i] != a[i - 1]);
    cout << ans << endl;
}

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

    int tc = 1;cin >> tc;
    while(tc--) solve_task();

    return 0;
}

Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: c++23 

Code 1:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    vector<int> nums(n);
    for (int &i: nums) {
      cin >> i;
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    sort(nums.begin(), nums.end());
    vector<int> cnt{1};
    int ans = 0;
    for (int i = 1; i < n; ++i) {
      if (nums[i] == nums[i - 1]) {
	++cnt.back();
      } else {
	cnt.emplace_back(1);
      }
    }
    sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    for (int i = 0; i < m - 1; ++i) {
      if (cnt[i] > k) {
	ans = m - i;
	break;
      }
      k -= cnt[i];
    }
    cout << max(ans, 1) << endl;
  }
}


Code 2:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data;
    for (auto &[k, v]: nums) {
      data.push_back({v, k});
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}


Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: c++20 

Code 1:
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

/*
stole from editorial, my intuition was correct about it being
"base state of ans is the num of unique elements, to get minimum value of f(a) we reduce
the number of unique elements", just that my implementation was incorrect.
*/

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

    int t{};
    std::cin >> t;
    while (t--)
    {
        int n{}, k{};
        std::cin >> n >> k;

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::sort(all(v));
        std::vector<int> cnt = {1};
        for (int i = 1; i < n; i++)
        {
            if (v[i] == v[i - 1])
                cnt.back()++;
            else
                cnt.emplace_back(1);
        }
        std::sort(all(cnt));
        int m = cnt.size(); bool chk{false};
        for (int i = 0; i < m - 1; i++)
        {
            if (cnt[i] > k)
            {
                std::cout << m - i << "\n";
                chk = true;
                break;
            }
            k -= cnt[i];
        }
        if(!chk)
           std::cout << 1 << "\n";
    }
}


Code 2:
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

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

    int t{};
    std::cin >> t;
    while (t--)
    {
        int n{}, k{};
        std::cin >> n >> k;

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::map<int, int> cnt{};
        for (int num : v)
           cnt[num]++;

        int ans = std::set(all(v)).size();
        std::vector<std::pair<int, int>> pairs(cnt.begin(), cnt.end());
        std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b)
        {
            return a.second < b.second;
        });

        for(int i = 0; i < pairs.size(); i++)
        {
            if(k <= 0)
                break;
            else
            {
                ans--;
                k -= pairs[i].second;
            }
        }

        if(ans == 0)
            std::cout << 1 << '\n';
        else
            std::cout << ans << '\n';
    }
}


Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: c++23 

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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  auto __solve=[&](int test){
    int n,k;
    cin>>n>>k;
    map<int,int> mp;
    for(int i=0;i<n;i++){
      int x;
      cin>>x;
      mp[x]++;
    }
    int size=mp.size();
    if(k>=n){
      cout<<1<<'\n';
      return;
    }
    vector<int> v(size);
    int ind=0,cnt=0;
    for(auto it:mp){
      v[ind]=it.second;
      ind++;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<size;i++){
      if(k>=v[i]){
        k-=v[i];
        cnt++;
      }
      else{
        break;
      }
    }

    cout<<size-cnt<<'\n';
  };
  
  int t=1;
  cin>>t;
  while(t--){
    __solve(t);
  }
    return 0;
}


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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  auto __solve=[&](int test){
    int n,k;
    cin>>n>>k;
    map<int,int> mp;
    for(int i=0;i<n;i++){
      int x;
      cin>>x;
      mp[x]++;
    }
    
    if(k>=n){
      cout<<1<<'\n';
      return;
    }
    int ans=0;
    for(auto &it:mp){
      ans+=(it.second+1)/2;
    }
    
    ans-=k;
    cout<<ans<<'\n';
  };
  
  int t=1;
  cin>>t;
  while(t--){
    __solve(t);
  }
    return 0;
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: c++20 

Code 1:
#include <iostream>				// Hello 2025 B
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#define ll long long
using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		mp[num]++;
	}
	for (auto i : mp) {
		a.push_back(i.second);
	}
	sort(a.begin(), a.end());
	int ans = a.size();
	int l = 0, r = a.size() - 1;
	while (k > 0 && l < r) {
		if (a[l] <= a[r]) {
			k -= a[l];
			l++, ans--;
		}
		else {
			k -= a[r];
			r--, ans--;
		}
	}
	if (k < 0) ans++;
	cout << ans << endl;
}

int main()
{
	int t;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

Code 2:
#include <iostream>				// Hello 2025 B
#include <vector>
#include <map>
#include <math.h>
#define ll long long
using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		mp[num]++;
	}
	for (auto i : mp) {
		a.push_back(i.second);
	}
	int ans = a.size();
	int l = 0, r = a.size() - 1;
	while (k > 0 && l < r) {
		if (a[l] <= a[r]) {
			k -= a[l];
			l++, ans--;
		}
		else {
			k -= a[r];
			r--, ans--;
		}
	}
	if (k < 0) ans++;
	cout << ans << endl;
}

int main()
{
	int t;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}

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

Code 1:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10,INF=0x3f3f3f3f,mod= 1e9 + 7;
/*int primes[N];bool st[N];int cnt=0;
void getpri(int n)
{
    for(int i=2;i<=n; i++)
    {
        if(!st[i]) primes[cnt++] = i;
        for(int j=0; primes[j] <= n/i; j++)
            {
            st[primes[j]*i]=true;
            if(i%primes[j]==0) break;
            }
    }
}*/
int qsm(int n,int m)/*n^m*/
{
    int res=1;
    while(m)
    {
        if(m&1) 
        res=res*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return res;
}
map<int,int>mp,mpp; 
void solve()
{
    mp.clear();
	int n,k;
    cin>>n>>k;
    if(n==k){cout<<1<<endl;return;}
    int cnt=0;
    int  a[N] = {0};
    vector<int>s;
    set<int>p;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(mp[a[i]]==0)cnt++,p.insert(a[i]);
        mp[a[i]]++;
        
    }//求种类数；

    for(auto l=p.begin();l!=p.end();l++)
    {
        s.push_back(mp[*l]);
    }//把元素个数取出来

    sort(s.begin(),s.end());//排序

    for(int i=0;i<s.size();i++)
    {
        if(k<s[i])break;
        if(k>=s[i])k-=s[i],cnt--;
    }
    cout<<cnt<<endl;
}
signed main() 
{
	ios::sync_with_stdio(0); cin.tie(0),cout.tie(0);
  	int T=1;
  	cin>>T;
  	while(T--)
  	{
  		solve();
	}
    return 0;
}

Code 2:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10,INF=0x3f3f3f3f,mod= 1e9 + 7;
/*int primes[N];bool st[N];int cnt=0;
void getpri(int n)
{
    for(int i=2;i<=n; i++)
    {
        if(!st[i]) primes[cnt++] = i;
        for(int j=0; primes[j] <= n/i; j++)
            {
            st[primes[j]*i]=true;
            if(i%primes[j]==0) break;
            }
    }
}*/
int qsm(int n,int m)/*n^m*/
{
    int res=1;
    while(m)
    {
        if(m&1) 
        res=res*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return res;
}
map<int,int>mp,mpp; 
void solve()
{
    mp.clear();
	int n,k;
    cin>>n>>k;
    int cnt=0;
    int  a[N] = {0};
    vector<int>p;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(mp[a[i]]==0)cnt++;
        mp[a[i]]++;
        
    }//求种类数；

    for(auto x:mp)
    {
        p.push_back(x.second);
    }//取出来种类数；

    sort(p.begin(),p.end());

    for(int i=0;i<p.size();i++)
    {
        if(k>=p[i])k-=p[i],cnt--;
    }
    cout<<max((int)1,cnt)<<endl;
}
signed main() 
{
	ios::sync_with_stdio(0); cin.tie(0),cout.tie(0);
  	int T=1;
  	cin>>T;
  	while(T--)
  	{
  		solve();
	}
    return 0;
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: python

Code 1:
if __name__ == "__main__":
    tc = 0
    tc = int(input())
    lres = []
    for i in range(tc):
        nkRaw = input()
        n = int(nkRaw.split(" ")[0])
        k = int(nkRaw.split(" ")[1])
        minimum = 0
        maximum = 1
        arrayRaw = input()
        array = arrayRaw.split(" ")
        diccionario = {}
        for num in range(int(n)):
            if(array[num] not in diccionario):
                diccionario[array[num]] = 1
            else:
                diccionario[array[num]] += 1;
        if(k >= len(diccionario)):
            lres.append(1)
            break
        else:
            sorted(diccionario.values())
            lista_diccionario = diccionario.values()
            aux = 0
            for num in lista_diccionario:
                if(num <= k):
                    k -= num
                    aux += 1
            lres.append(len(lista_diccionario) - aux)
    for res in lres:
        print(res)
            
        
        
# end main

Code 2:
if __name__ == "__main__":
    tc = 0
    tc = int(input())
    lres = []
    for i in range(tc):
        nkRaw = input()
        n = int(nkRaw.split(" ")[0])
        k = int(nkRaw.split(" ")[1])
        minimum = 0
        maximum = 1
        arrayRaw = input()
        array = arrayRaw.split(" ")
        diccionario = {}
        for num in range(int(n)):
            if(array[num] not in diccionario):
                diccionario[array[num]] = 1
            else:
                diccionario[array[num]] += 1;
        if(k >= n):
            lres.append(1)
        else:
            lista_diccionario = sorted(diccionario.values())
            aux = 0
            for num in lista_diccionario:
                if(num <= k):
                    k -= num
                    aux += 1
                else:
                    break
            lres.append(len(lista_diccionario) - aux)
    for res in lres:
        print(res)
#end

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

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

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

    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        map<int, int> freq;

        // Count occurrences
        for (int i = 0; i < n; i++) {
            int temp;
            cin >> temp;
            freq[temp]++;
        }

        // Extract frequencies and sort them
        vector<int> counts;
        for (auto &[num, count] : freq) {
            counts.push_back(count);
        }
        sort(counts.begin(), counts.end());

        int ans = counts.size();
        int i = 0;

        // Greedily remove smallest frequency elements
        while (i < counts.size() && k >= counts[i]) {
            k -= counts[i];
            ans--;
            i++;
        }

        cout << max(1, ans) << "\n";
    }
    return 0;
}

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

int main() {
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int ans=0;
        unordered_map<int,int> m;
        for(int i=0;i<n;i++){
            int temp;
            cin>>temp;
            m[temp]+=1;
        }
        vector<int> v;
        for(auto i:m){
            v.push_back(i.second);
        }
        sort(v.begin(),v.end());
        ans=v.size();
        for(auto i:v){
            cout<<i<<",";
        }
        cout<<"\n";
        int h=0;
        while(k){
            if(v[h]<=k){
                k-=v[h];
                ans-=1;
            }
            else k=0;
            h+=1;
        }
        if(ans<=0) cout<<"1"<<"\n";
        else cout<<ans<<"\n";
    }
    return 0;
}

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

Code 1:
#include <bits/stdc++.h>

using namespace std;

int f(vector<int>& b) {
    int n = b.size();
    if (n == 0) return 0;

    vector<int> dp(n + 1, INT_MAX);
    dp[0] = 0;

    for (int i = 1; i <= n; ++i) {
        int min_val = INT_MAX;
        for (int j = i; j > 0; --j) {
            min_val = min(min_val, b[j - 1]);
            dp[i] = min(dp[i], dp[j - 1] + 1);
        }
    }

    return dp[n];
}

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) {
         int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> a;
    for (int j = 0; j < n; ++j) {
        int x;
        cin >> x;
        a.push_back(x);
    }
       
    // Example usage of f(b)
    cout << f(a) << endl;}

    return 0;
}

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

void solve() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        map<int, int> freq;
        
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            freq[a[i]]++;
        }
        
        if (n == k) {
            // If n == k, we can include all elements
            cout << 1 << endl;
            continue;
        }
        
        vector<int> counts;
        for (const auto& pair : freq) {
            counts.push_back(pair.second);
        }
        
        sort(counts.begin(), counts.end());
        
        int removable = 0;
        int total = 0;
        for (int count : counts) {
            if (total + count <= k) {
                total += count;
                removable++;
            } else {
                break;
            }
        }
        
        int result = freq.size() - removable;
        cout << result << endl;
    }
}

int main() {
    solve();
    return 0;
}


Answer: 2