ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>
using namespace std;
#define int long long

/*void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	sort(a,a+r+1);
	/**for(int i=0;i<n;++i){
		cout<<a[i]<<" ";
	}
	cout<<endl;
	int sum=accumulate(a,a+z,0);
	sort(a+l,a+n);
	int s=0;
	for(int i=l;i<l+z;++i){
		s+=a[i];
	}
	sum=min(sum,s);
	cout<<sum<<endl;
   
   }**/
void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	vector<int> b,c;
	for(int i=0;i<=r;++i){
       b.push_back(a[i]);
	}
	for(int i=l;i<n;++i){
		c.push_back(a[i]);
	}
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	
	int s1=accumulate(b.begin(),b.begin()+z,0);
	int s2=accumulate(c.begin(),c.begin()+z,0);
	int sum=min(s1,s2);
	cout<<sum<<endl;
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long

/*void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	sort(a,a+r+1);
	/**for(int i=0;i<n;++i){
		cout<<a[i]<<" ";
	}
	cout<<endl;
	int sum=accumulate(a,a+z,0);
	sort(a+l,a+n);
	int s=0;
	for(int i=l;i<l+z;++i){
		s+=a[i];
	}
	sum=min(sum,s);
	cout<<sum<<endl;
   
   }**/
void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	vector<int> b,c;
	for(int i=0;i<=r;++i){
       b.push_back(a[i]);
	}
	for(int i=l;i<n;++i){
		c.push_back(a[i]);
	}
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	
	int s1=accumulate(b.begin(),b.begin()+z,0ll);
	int s2=accumulate(c.begin(),c.begin()+z,0ll);
	int sum=min(s1,s2);
	cout<<sum<<endl;
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n+1];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	sort(a,a+r+1);
	/**for(int i=0;i<n;++i){
		cout<<a[i]<<" ";
	}
	cout<<endl;**/
	int sum=accumulate(a,a+z,0);
	sort(a+l,a+n);
	int s=0;
	for(int i=l;i<l+z;++i){
		s+=a[i];
	}
	sum=min(sum,s);
	cout<<sum<<endl;
   
   }

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	sort(a,a+r+1);
	/**for(int i=0;i<n;++i){
		cout<<a[i]<<" ";
	}
	cout<<endl;**/
	int sum=accumulate(a,a+z,0);
	sort(a+l,a+n);
	int s=0;
	for(int i=l;i<l+z;++i){
		s+=a[i];
	}
	sum=min(sum,s);
	cout<<sum<<endl;
   
   }

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	sort(a,a+r+1);
	/**for(int i=0;i<n;++i){
		cout<<a[i]<<" ";
	}
	cout<<endl;**/
	int sum=accumulate(a,a+z,0);
	sort(a+l,a+n);
	int s=0;
	for(int i=l;i<l+z;++i){
		s+=a[i];
	}
	sum=min(sum,s);
	cout<<sum<<endl;
   
   }

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>
using namespace std;
#define int long long

/*void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	sort(a,a+r+1);
	/**for(int i=0;i<n;++i){
		cout<<a[i]<<" ";
	}
	cout<<endl;
	int sum=accumulate(a,a+z,0);
	sort(a+l,a+n);
	int s=0;
	for(int i=l;i<l+z;++i){
		s+=a[i];
	}
	sum=min(sum,s);
	cout<<sum<<endl;
   
   }**/
void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	l--,r--;
	int a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	int z=r-l+1;
	vector<int> b,c;
	for(int i=0;i<=r;++i){
       b.push_back(a[i]);
	}
	for(int i=l;i<n;++i){
		c.push_back(a[i]);
	}
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	
	int s1=accumulate(b.begin(),b.begin()+z,0);
	int s2=accumulate(c.begin(),c.begin()+z,0);
	int sum=min(s1,s2);
	cout<<sum<<endl;
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    int ele = mp.size();
    if(ele >= k){
        return 1;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;



int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    int distinctEle = 1;
    for(int i = 0;i<n-1;i++){
        if(a[i] != a[i+1]){
            distinctEle++;
        }
    }
    if( (distinctEle - 1) <= k){
        return 1;
    }
    return (distinctEle - k);
}




int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    int ele = mp.size();
    if(ele >= k){
        return 1;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    int ele = mp.size();
    if(ele <= k){
        return 1;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;



int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    int distinctEle = 1;
    for(int i = 0;i<n-1;i++){
        if(a[i] != a[i+1]){
            distinctEle++;
        }
    }
    if( (distinctEle - 1) <= k){
        return 1;
    }
    return (distinctEle - k);
}




int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    int ele = mp.size();
    if(ele <= k){
        return 1;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;

int solve(){
    int n,k;
    vector<int> a;
    cin>>n>>k;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    priority_queue<int,vector<int>,greater<int>> pq;
    map<int,int> mp;
    for(auto x : a){
        mp[x]++;
    }
    for(auto x : mp){
        pq.push(x.second);
    }
    while(!pq.empty() && k>=pq.top()){
        int p = pq.top();
        pq.pop();
        k -= p;
    }
    return pq.empty() ? 1 : pq.size();
}

    int main(){
    int t;
    cin>>t;
    while(t--){
        int ans = solve();
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

    if(x>y)swap(x,y);

    for(int i=0; i<n; i++){

        if(i&1)v[i]=0;

        else v[i]=1;

    }

    if(n&1)v[n-1]=2;

    if(v[x-1]==v[y-1] ){

        v[y-1]=2;

    }

    for(int i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

    

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

    x--,y--;

    for(int i=0; i<n; i++){

        v[(x + i) % n] = i % 2;

    }

    if (n % 2 || (x - y) % 2 == 0)

        v[x] = 2;

    for(int i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

    

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

   

    if(x&1 && y&1){

        v[x-1]=0;

        v[y-1]=2;

    }else{

        v[x-1]=1;

        v[y-1]=2;

    }

    int i=x-2;

    while(i>=0){

        if(v[i+1]==0){

            v[i]=1;

        }else{

            v[i]=0;

        }

        i--;

    }

    i=x;

    while(i<y-1){

        if(v[i-1]==0){

            v[i]=1;

        }else{

            v[i]=0;

        }

        i++;

    }

    i=y;

    while(i<n){

        if(v[i-1]==0){

            v[i]=1;

        }else{

            v[i]=0;

        }

        i++;

    }

    for(i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

    for(int i=0; i<n; i++){

        if(i&1)v[i]=1;

        else v[i]=0;

    }

    if(n&1)v[n-1]=2;

    if(x&1 && y&1 ){

        v[y-1]=2;

    }else if(!(x&1) && !(y&1)){

       v[y-1]=2;

    }

    for(int i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

    

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

    for(int i=0; i<n; i++){

        if(i&1)v[i]=1;

        else v[i]=0;

    }

    if(n&1)v[n-1]=2;

    if(x&1 && y&1 ){

        v[y-1]=2;

    }else if(!(x&1) && !(y&1)){

       v[y-1]=2;

    }

    for(int i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

    

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

    if(x>y)swap(x,y);

    for(int i=0; i<n; i++){

        if(i&1)v[i]=0;

        else v[i]=1;

    }

    if(n&1)v[n-1]=2;

    if(v[x-1]==v[y-1] ){

        v[y-1]=2;

    }

    for(int i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

    

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define ff first

#define ss second

#define pii pair<int,int>

#define vi vector<int>

#define vii vector<pair<int,int>>



void solve()

{

    int n,x,y;

    cin >> n>>x>>y;

    vi v(n);

   

    if(x&1 && y&1){

        v[x-1]=0;

        v[y-1]=2;

    }else{

        v[x-1]=1;

        v[y-1]=2;

    }

    int i=x-2;

    while(i>=0){

        if(v[i+1]==0){

            v[i]=1;

        }else{

            v[i]=0;

        }

        i--;

    }

    i=x;

    while(i<y-1){

        if(v[i-1]==0){

            v[i]=1;

        }else{

            v[i]=0;

        }

        i++;

    }

    i=y;

    while(i<n){

        if(v[i-1]==0){

            v[i]=1;

        }else{

            v[i]=0;

        }

        i++;

    }

    for(i=0; i<v.size(); i++){

        cout<<v[i]<<" ";

    }

    cout<<endl;

    

    

}

signed main()

{

    int tcs;

    cin >> tcs;

    while (tcs--)

    {

        solve();

    }

}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 4):
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>

using namespace std;

void fastIO() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
}

int main()
{
	fastIO();

	int t;
	cin >> t;

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

		vector <pair<int, int>> p(n);
		unordered_map<int, int> m;

		
		while (n--)
		{
			int temp;
			cin >> temp;

			if (++m[temp] == 1)
			{
				p.push_back({temp, m[temp]});
			}
			else
			{
				for (int i{ 0 }; i < p.size(); ++i)
				{
					if (p[i].first == temp)
					{
						p[i].second = m[temp];
						break;
					}
				}
			}
			
		}

		if (n == 1)
		{
			cout << 1 << "\n";
			continue;
		}
		
		std::sort(p.begin(), p.end(), [](const std::pair<int, int>& a, const std::pair<int, int>& b) {
			return a.second < b.second;
			});

		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (k > 0)
			{

				if (p[i].second > k)
					break;
				else
				{
					k -= p[i].second;
					p[i].second = 0;
				}
			}
			else
				break;
		}

		int count{ 0 };
		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (p[i].second != 0)
				++count;
		}

		if (count == 0)
			count = 1;

		cout << count << "\n";
	}
}

Submission (verdict: Accepted):
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;



int main()
{

	int t;
	cin >> t;

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

		map<int, int> m;
		
		while(n--)
		{

			int temp;
			cin >> temp;

			++m[temp];
		}

		vector<pair<int, int>> p(m.begin(), m.end());
		
		int count{ (int)m.size() };

		sort(p.begin(), p.end(), [](const pair<int, int>& a, const pair<int, int>& b)
		{
			return a.second < b.second;
		});
		
		
		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (k > 0 && count > 1)
			{
				if (k >= p[i].second)
				{
					k -= p[i].second;
					--count;
				}
				else
					break;
			}
			else
				break;
		}
		
			

		cout << count << "\n\n";
	}
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 4):
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>

using namespace std;

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

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

		vector <pair<int, int>> p(n);
		unordered_map<int, int> m;

		
		while (n--)
		{
			int temp;
			cin >> temp;

			if (++m[temp] == 1)
			{
				p.push_back({temp, m[temp]});
			}
			else
			{
				for (int i{ 0 }; i < p.size(); ++i)
				{
					if (p[i].first == temp)
					{
						p[i].second = m[temp];
						break;
					}
				}
			}
			
		}

		if (n == 1)
		{
			cout << 1 << "\n";
			continue;
		}
		
		std::sort(p.begin(), p.end(), [](const std::pair<int, int>& a, const std::pair<int, int>& b) {
			return a.second < b.second;
			});

		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (k > 0)
			{

				if (p[i].second > k)
					break;
				else
				{
					k -= p[i].second;
					p[i].second = 0;
				}
			}
			else
				break;
		}

		int count{ 0 };
		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (p[i].second != 0)
				++count;
		}

		if (count == 0)
			count = 1;

		cout << count << "\n";
	}
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 4):
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>

using namespace std;

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

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

		vector <pair<int, int>> p(n);
		unordered_map<int, int> m;

		
		while (n--)
		{
			int temp;
			cin >> temp;

			if (++m[temp] == 1)
			{
				p.push_back({temp, m[temp]});
			}
			else
			{
				for (int i{ 0 }; i < p.size(); ++i)
				{
					if (p[i].first == temp)
					{
						p[i].second = m[temp];
						break;
					}
				}
			}
			
		}

		if (n == 1)
		{
			cout << 1 << "\n";
			continue;
		}
		
		std::sort(p.begin(), p.end(), [](const std::pair<int, int>& a, const std::pair<int, int>& b) {
			return a.second < b.second;
			});

		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (k > 0)
			{

				if (p[i].second > k)
					break;
				else
				{
					k -= p[i].second;
					p[i].second = 0;
				}
			}
			else
				break;
		}

		int count{ 0 };
		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (p[i].second != 0)
				++count;
		}

		if (count == 0)
			count = 1;

		cout << count << "\n";
	}
}

Submission (verdict: Time limit exceeded on test 4):
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>

using namespace std;

void fastIO() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
}

int main()
{
	fastIO();

	int t;
	cin >> t;

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

		vector <pair<int, int>> p(n);
		unordered_map<int, int> m;

		
		while (n--)
		{
			int temp;
			cin >> temp;

			if (++m[temp] == 1)
			{
				p.push_back({temp, m[temp]});
			}
			else
			{
				for (int i{ 0 }; i < p.size(); ++i)
				{
					if (p[i].first == temp)
					{
						p[i].second = m[temp];
						break;
					}
				}
			}
			
		}

		if (n == 1)
		{
			cout << 1 << "\n";
			continue;
		}
		
		std::sort(p.begin(), p.end(), [](const std::pair<int, int>& a, const std::pair<int, int>& b) {
			return a.second < b.second;
			});

		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (k > 0)
			{

				if (p[i].second > k)
					break;
				else
				{
					k -= p[i].second;
					p[i].second = 0;
				}
			}
			else
				break;
		}

		int count{ 0 };
		for (int i{ 0 }; i < p.size(); ++i)
		{
			if (p[i].second != 0)
				++count;
		}

		if (count == 0)
			count = 1;

		cout << count << "\n";
	}
}