ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 8):
#include <bits/stdc++.h>

using namespace std;



int main(){

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t; cin>>t;

while(t--){

string s1; cin>>s1;

int n= s1.length();

while (1){

bool sw=true;

for (int i=n-1;i>0;i--){

// cout<<i-1<<" "<<i<<endl;;

// cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

if (s1[i]>s1[i-1]+1){

s1[i]= s1[i]-1;

swap(s1[i],s1[i-1]);

// cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

// cout<<s1<<endl;

i--;

sw=false;

// cout<<s1<<" ";

}

}

if (sw){

break;

}

}

cout<<s1<<endl;

}

}

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

// using namespace std;



// int main(){

//     ios::sync_with_stdio(false);

//     cin.tie(nullptr);

//     int t; cin>>t;

//     while(t--){

//         string s1; cin>>s1;

//         int n= s1.length();

//         while (1){

//             bool sw=true;

//             for (int i=n-1;i>0;i--){

//                 // cout<<i-1<<" "<<i<<endl;;

//                 // cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

//                 if (s1[i]>s1[i-1]+1){

//                     s1[i]= s1[i]-1;

//                     swap(s1[i],s1[i-1]);

//                     // cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

//                     // cout<<s1<<endl;

//                     i--;

//                     sw=false;

//                     // cout<<s1<<" ";

//                 }

//             }

//             if (sw){

//                 break;

//             }

//         }

//         cout<<s1<<endl;

//     }

// }

#include <bits/stdc++.h>

using namespace std;



int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);



int t;cin >> t;



while (t--) {

string s; cin >> s;

int n = s.length();

int i=1;



while (i < n) {

//bool sw=true;

// cout<<i-1<<" "<<i<<endl;;

// cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

if (s[i] > s[i - 1] + 1) {

s[i]--;

swap(s[i], s[i - 1]);

// cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

// cout<<s1<<endl;

if (i>1){

i--;

}

else{

i=1;

}

}

else {

i++;

}

//          if (sw){

//                 break;

//             }

}

cout << s << endl;

}

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;



int main(){

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t; cin>>t;

while(t--){

string s1; cin>>s1;

int n= s1.length();

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

bool sw=true;

for (int i=n-1;i>0;i--){

// cout<<i-1<<" "<<i<<endl;;

// cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

if (s1[i]>s1[i-1]+1){

s1[i]= s1[i]-1;

swap(s1[i],s1[i-1]);

// cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

// cout<<s1<<endl;

i--;

sw=false;

// cout<<s1<<" ";

}

}

if (sw){

break;

}

}

cout<<s1<<endl;

}

}

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

using namespace std;



int main(){

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t; cin>>t;

while(t--){

string s1; cin>>s1;

int n= s1.length();

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

bool sw=true;

for (int i=n-1;i>0;i--){

// cout<<i-1<<" "<<i<<endl;;

// cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

if (s1[i]>s1[i-1]+1){

s1[i]= s1[i]-1;

swap(s1[i],s1[i-1]);

// cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

// cout<<s1<<endl;

i--;

sw=false;

// cout<<s1<<" ";

}

}

if (sw){

break;

}

}

cout<<s1<<endl;

}

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;



int main(){

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t; cin>>t;

while(t--){

string s1; cin>>s1;

int n= s1.length();

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

bool sw=true;

for (int i=n-1;i>0;i--){

// cout<<i-1<<" "<<i<<endl;;

// cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

if (s1[i]>s1[i-1]+1){

s1[i]= s1[i]-1;

swap(s1[i],s1[i-1]);

// cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

// cout<<s1<<endl;

i--;

sw=false;

// cout<<s1<<" ";

}

}

if (sw){

break;

}

}

cout<<s1<<endl;

}

}

Submission (verdict: Time limit exceeded on test 8):
#include <bits/stdc++.h>

using namespace std;



int main(){

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t; cin>>t;

while(t--){

string s1; cin>>s1;

int n= s1.length();

while (1){

bool sw=true;

for (int i=n-1;i>0;i--){

// cout<<i-1<<" "<<i<<endl;;

// cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

if (s1[i]>s1[i-1]+1){

s1[i]= s1[i]-1;

swap(s1[i],s1[i-1]);

// cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

// cout<<s1<<endl;

i--;

sw=false;

// cout<<s1<<" ";

}

}

if (sw){

break;

}

}

cout<<s1<<endl;

}

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;



int main(){

ios::sync_with_stdio(false);

cin.tie(nullptr);

int t; cin>>t;

while(t--){

string s1; cin>>s1;

int n= s1.length();

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

bool sw=true;

for (int i=n-1;i>0;i--){

// cout<<i-1<<" "<<i<<endl;;

// cout<<"original "<<s1[i-1]<<" "<<s1[i]<<endl;

if (s1[i]>s1[i-1]+1){

s1[i]= s1[i]-1;

swap(s1[i],s1[i-1]);

// cout<<"after swap "<<s1[i-1]<<" "<<s1[i]<<endl;

// cout<<s1<<endl;

i--;

sw=false;

// cout<<s1<<" ";

}

}

if (sw){

break;

}

}

cout<<s1<<endl;

}

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;

void solve()
{
    string s;
    cin >> s;
    int n = s.size();

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

        for (int j = 0; j < n - 1; j++)
        {
            if ((s[j] + 1) < s[j + 1])
            {
                s[j + 1]--;
                swap(s[j], s[j + 1]);
            }
        }
    }
    cout << s << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();

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

            for (int j = 0; j < n - 1; j++)
            {
                if ((s[j] + 1) < s[j + 1])
                {
                    s[j + 1]--;
                    swap(s[j], s[j + 1]);
                }
            }
        }
        cout << s << endl;
    }
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();

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

            for (int j = 0; j < n - 1; j++)
            {
                if ((s[j] + 1) < s[j + 1])
                {
                    s[j + 1]--;
                    swap(s[j], s[j + 1]);
                }
            }
        }
        cout << s << endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;

void solve()
{
    string s;
    cin >> s;
    int n = s.size();

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

        for (int j = 0; j < n - 1; j++)
        {
            if ((s[j] + 1) < s[j + 1])
            {
                s[j + 1]--;
                swap(s[j], s[j + 1]);
            }
        }
    }
    cout << s << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();

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

            for (int j = 0; j < n - 1; j++)
            {
                if ((s[j] + 1) < s[j + 1])
                {
                    s[j + 1]--;
                    swap(s[j], s[j + 1]);
                }
            }
        }
        cout << s << endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <cstdio>
#include <bits/stdc++.h>
 
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long,long> pll;
 
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<long long>
#define mii map<int, int>
 
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.14159265358979323846

ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }

void solve() {
  int n, l, r; cin >> n >> l >> r;
  vll a(n); f(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll sm = 0;
  f(i, 0, r - l + 1) sm += a[i];
  cout << sm << '\n';
}

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

Submission (verdict: Wrong answer on test 8):
#include <cstdio>

#include <bits/stdc++.h>

 

using namespace std;

typedef vector<int> vi;

typedef vector<char> vc;

typedef vector<long long> vll;

typedef pair<int,int> pi;

typedef pair<long,long> pll;

 

#define ll long long

#define pii pair<int, int>

#define pll pair<long long, long long>

#define vi vector<int>

#define vb vector<bool>

#define vll vector<long long>

#define mii map<int, int>

 

#define f(i,s,e) for(long long int i=s;i<e;i++)

#define cf(i,s,e) for(long long int i=s;i<=e;i++)

#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)

#define pb push_back

#define eb emplace_back

#define mp make_pair

#define mt make_tuple

#define MOD 1000000007

#define PI 3.14159265358979323846



ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }

ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }

void yes() { cout<<"YES\n"; }

void no() { cout<<"NO\n"; }



void solve() {

  int n, l, r; cin >> n >> l >> r;

  l--; r--;

  vll a(n); f(i, 0, n) cin >> a[i];

  vll x, y;

  cf(i, 0, r) x.pb(a[i]);

  f(i, l, n) y.pb(a[i]);

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

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

  int sz = r - l + 1;

  ll sm1 = accumulate(x.begin(), x.begin() + sz, 0);

  ll sm2 = accumulate(y.begin(), y.begin() + sz, 0);

  cout << min(sm1, sm2) << "\n";

}



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0);

  int t = 1; 

  cin >> t;

  while (t--) solve();

  return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include <cstdio>

#include <bits/stdc++.h>

 

using namespace std;

typedef vector<int> vi;

typedef vector<char> vc;

typedef vector<long long> vll;

typedef pair<int,int> pi;

typedef pair<long,long> pll;

 

#define ll long long

#define pii pair<int, int>

#define pll pair<long long, long long>

#define vi vector<int>

#define vb vector<bool>

#define vll vector<long long>

#define mii map<int, int>

 

#define f(i,s,e) for(long long int i=s;i<e;i++)

#define cf(i,s,e) for(long long int i=s;i<=e;i++)

#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)

#define pb push_back

#define eb emplace_back

#define mp make_pair

#define mt make_tuple

#define MOD 1000000007

#define PI 3.14159265358979323846



ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }

ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }

void yes() { cout<<"YES\n"; }

void no() { cout<<"NO\n"; }



void solve() {

  int n, l, r; cin >> n >> l >> r;

  l--; r--;

  vll a(n); f(i, 0, n) cin >> a[i];

  vll x, y;

  cf(i, 0, r) x.pb(a[i]);

  f(i, l, n) y.pb(a[i]);

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

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

  int sz = r - l + 1;

  ll sm1 = accumulate(x.begin(), x.begin() + sz, 0);

  ll sm2 = accumulate(y.begin(), y.begin() + sz, 0);

  cout << min(sm1, sm2) << "\n";

}



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0);

  int t = 1; 

  cin >> t;

  while (t--) solve();

  return 0;

}

 

Submission (verdict: Accepted):
#include <cstdio>
#include <bits/stdc++.h>
 
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long,long> pll;
 
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<long long>
#define mii map<int, int>
 
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.14159265358979323846

ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }

void solve() {
  int n, l, r; cin >> n >> l >> r;
  l--; r--;
  vll a(n); f(i, 0, n) cin >> a[i];
  vll x, y;
  cf(i, 0, r) x.pb(a[i]);
  f(i, l, n) y.pb(a[i]);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  int sz = r - l + 1;
  ll sm1 = accumulate(x.begin(), x.begin() + sz, 0LL);
  ll sm2 = accumulate(y.begin(), y.begin() + sz, 0LL);
  cout << min(sm1, sm2) << "\n";
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1; 
  cin >> t;
  while (t--) solve();
  return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <cstdio>
#include <bits/stdc++.h>
 
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long,long> pll;
 
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<long long>
#define mii map<int, int>
 
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.14159265358979323846

ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }

void solve() {
  int n, l, r; cin >> n >> l >> r;
  vll a(n); f(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll sm = 0;
  f(i, 0, r - l + 1) sm += a[i];
  cout << sm << '\n';
}

 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1; 
  cin >> t;
  while (t--) solve();
  return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int N=2e5+5;
vector<ll>n1[N];
set<ll>vis;
ll pla,pla1;
void bfs(ll now,ll fa){
    vis.insert(now);
    for(auto num:n1[now]){
        if(num==fa || num==pla || num==pla1)continue;
        bfs(num,now);
    }
}
void solve(){
    vis.clear();
    ll m,mx=-1;
    pla=0;
    cin>>m;
    for(int i=1;i<m;i++){
        ll a,b;
        cin>>a>>b;
        n1[a].push_back(b);
        n1[b].push_back(a);
        if((ll)n1[a].size()>mx){
            mx=n1[a].size();
            pla=a;
        }
        if((ll)n1[b].size()>mx){
            mx=n1[b].size();
            pla=b;
        }
    }
    // cout<<mx<<'\n';
    //mx删掉
    ll mx1=-1;
    pla1=0;
    for(int i=1;i<=m;i++){
        if(i==pla)continue;
        ll number=0;
        for(auto num:n1[i]){
            if(num!=pla)number++;
        }
        if(number>mx1){
            mx1=number;
            pla1=i;
        }
    }
    
    ll res=0;
    for(int i=1;i<=m;i++){
        if(i==pla || i==pla1)continue;
        if(!vis.count(i)){
            // cout<<i<<'\n';
            res++;
            bfs(i,i);
        }
    }
    cout<<res<<'\n';
    for(int i=1;i<=m;i++)n1[i].clear();
}  
int main(){
    ios::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: Compilation error):
#include<bits/stdc++.h>
using namespace std;
#define fr(ii,ss,tt) for(int ii=ss;ii<=tt;ii++)
#define rf(ii,ss,tt) for(int ii=ss;ii>=tt;ii--)
#define pii pair<int,int>
#define pt printf
#define x first
#define y second
#define all(a) begin(a),end(a)
#define pb push_back
#define eb emplace_back
#define siz(x) ((int)size(x))
#ifdef UFILE
#define file(f1,f2) (f1!=""&&freopen(f1,"r",stdin),f2!=""&&freopen(f2,"w",stdout))
#else
#define file(...) 0
#endif
#ifdef DEBUG
#include DEBUG
#else
#define assert(...) 0
#define Z(...) 0
#define ZZ(...) 0
#endif
typedef long long LL;
typedef __int128 Int;
template<typename T>bool tomax(T&x,const T&y){if(x<y)return x=y,true;return false;}
template<typename T>bool tomin(T&x,const T&y){if(x>y)return x=y,true;return false;}
inline void rd(auto&x,auto&...y){char ch;bool f=0;while(!isdigit(ch=getchar()))if(ch=='-')f=1;x=0;do{x=(x<<1)+(x<<3)+(ch^48);}while(isdigit(ch=getchar()));if(f)x=-x;if constexpr(sizeof...(y))rd(y...);}
inline void wtl(auto&x,auto&...y){cout<<x;if constexpr(sizeof...(y))cout<<' ',wt(y...);else cout<<'\n';}

const int N=1e6+33;
int n,k,a[N];
signed main(){
	ios::sync_with_stdio(0);
	int T;
	rd(T);
	while(T--){
		rd(n,k);
		
		map<int,int>mp;
		fr(i,1,n){
			rd(a[i]);
			mp[a[i]]++;
		}if(k==n){
			pt("1\n");continue;
		}
		priority_queue<pii,vector<pii>,greater<pii>>q;
		for(auto[v,c]:mp){
			q.push({c,v});
		}
		while(1){
			auto[c,v]=q.top();
			if(c>k)break;
			q.pop();
			k-=c;
		}
		pt("%d\n",q.size());
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define fr(ii,ss,tt) for(int ii=ss;ii<=tt;ii++)
#define rf(ii,ss,tt) for(int ii=ss;ii>=tt;ii--)
#define pii pair<int,int>
#define pt printf
#define x first
#define y second
#define all(a) begin(a),end(a)
#define pb push_back
#define eb emplace_back
#define siz(x) ((int)size(x))
#ifdef UFILE
#define file(f1,f2) (f1!=""&&freopen(f1,"r",stdin),f2!=""&&freopen(f2,"w",stdout))
#else
#define file(...) 0
#endif
#ifdef DEBUG
#include DEBUG
#else
#define assert(...) 0
#define Z(...) 0
#define ZZ(...) 0
#endif
typedef long long LL;

template<typename T>bool tomax(T&x,const T&y){if(x<y)return x=y,true;return false;}
template<typename T>bool tomin(T&x,const T&y){if(x>y)return x=y,true;return false;}
inline void rd(auto&x,auto&...y){char ch;bool f=0;while(!isdigit(ch=getchar()))if(ch=='-')f=1;x=0;do{x=(x<<1)+(x<<3)+(ch^48);}while(isdigit(ch=getchar()));if(f)x=-x;if constexpr(sizeof...(y))rd(y...);}
inline void wtl(auto&x,auto&...y){cout<<x;if constexpr(sizeof...(y))cout<<' ',wt(y...);else cout<<'\n';}

const int N=1e6+33;
int n,k,a[N];
signed main(){
	ios::sync_with_stdio(0);
	int T;
	rd(T);
	while(T--){
		rd(n,k);
		
		map<int,int>mp;
		fr(i,1,n){
			rd(a[i]);
			mp[a[i]]++;
		}if(k==n){
			pt("1\n");continue;
		}
		priority_queue<pii,vector<pii>,greater<pii>>q;
		for(auto[v,c]:mp){
			q.push({c,v});
		}
		while(1){
			auto[c,v]=q.top();
			if(c>k)break;
			q.pop();
			k-=c;
		}
		pt("%d\n",q.size());
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include<bits/stdc++.h>
using namespace std;
#define fr(ii,ss,tt) for(int ii=ss;ii<=tt;ii++)
#define rf(ii,ss,tt) for(int ii=ss;ii>=tt;ii--)
#define pii pair<int,int>
#define pt printf
#define x first
#define y second
#define all(a) begin(a),end(a)
#define pb push_back
#define eb emplace_back
#define siz(x) ((int)size(x))
#ifdef UFILE
#define file(f1,f2) (f1!=""&&freopen(f1,"r",stdin),f2!=""&&freopen(f2,"w",stdout))
#else
#define file(...) 0
#endif
#ifdef DEBUG
#include DEBUG
#else
#define assert(...) 0
#define Z(...) 0
#define ZZ(...) 0
#endif
typedef long long LL;
typedef __int128 Int;
template<typename T>bool tomax(T&x,const T&y){if(x<y)return x=y,true;return false;}
template<typename T>bool tomin(T&x,const T&y){if(x>y)return x=y,true;return false;}
inline void rd(auto&x,auto&...y){char ch;bool f=0;while(!isdigit(ch=getchar()))if(ch=='-')f=1;x=0;do{x=(x<<1)+(x<<3)+(ch^48);}while(isdigit(ch=getchar()));if(f)x=-x;if constexpr(sizeof...(y))rd(y...);}
inline void wtl(auto&x,auto&...y){cout<<x;if constexpr(sizeof...(y))cout<<' ',wt(y...);else cout<<'\n';}

const int N=1e6+33;
int n,k,a[N];
signed main(){
	ios::sync_with_stdio(0);
	int T;
	rd(T);
	while(T--){
		rd(n,k);
		if(k==n){
			pt("1\n");continue;
		}
		map<int,int>mp;
		fr(i,1,n){
			rd(a[i]);
			mp[a[i]]++;
		}
		priority_queue<pii,vector<pii>,greater<pii>>q;
		for(auto[v,c]:mp){
			q.push({c,v});
		}
		while(1){
			auto[c,v]=q.top();
			if(c>k)break;
			q.pop();
			k-=c;
		}
		pt("%d\n",q.size());
	}
	return 0;
}

Submission (verdict: Runtime error on test 2):
#include<bits/stdc++.h>
using namespace std;
#define fr(ii,ss,tt) for(int ii=ss;ii<=tt;ii++)
#define rf(ii,ss,tt) for(int ii=ss;ii>=tt;ii--)
#define pii pair<int,int>
#define pt printf
#define x first
#define y second
#define all(a) begin(a),end(a)
#define pb push_back
#define eb emplace_back
#define siz(x) ((int)size(x))
#ifdef UFILE
#define file(f1,f2) (f1!=""&&freopen(f1,"r",stdin),f2!=""&&freopen(f2,"w",stdout))
#else
#define file(...) 0
#endif
#ifdef DEBUG
#include DEBUG
#else
#define assert(...) 0
#define Z(...) 0
#define ZZ(...) 0
#endif
typedef long long LL;
template<typename T>bool tomax(T&x,const T&y){if(x<y)return x=y,true;return false;}
template<typename T>bool tomin(T&x,const T&y){if(x>y)return x=y,true;return false;}
inline void rd(auto&x,auto&...y){char ch;bool f=0;while(!isdigit(ch=getchar()))if(ch=='-')f=1;x=0;do{x=(x<<1)+(x<<3)+(ch^48);}while(isdigit(ch=getchar()));if(f)x=-x;if constexpr(sizeof...(y))rd(y...);}
inline void wtl(auto&x,auto&...y){cout<<x;if constexpr(sizeof...(y))cout<<' ',wt(y...);else cout<<'\n';}

const int N=1e6+33;
int n,k,a[N];
signed main(){
	ios::sync_with_stdio(0);
	int T;
	rd(T);
	while(T--){
		rd(n,k);
		if(k==n){
			pt("1\n");continue;
		}
		map<int,int>mp;
		fr(i,1,n){
			rd(a[i]);
			mp[a[i]]++;
		}
		priority_queue<pii,vector<pii>,greater<pii>>q;
		for(auto[v,c]:mp){
			q.push({c,v});
		}
		while(1){
			auto[c,v]=q.top();
			if(c>k)break;
			q.pop();
			k-=c;
		}
		pt("%d\n",q.size());
	}
	return 0;
}