ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 202 ms):
// C++ program to demonstrate working of 

// extended Euclidean Algorithm 

#include <bits/stdc++.h> 

using namespace std;

typedef long long l1;

int main()  { 

  int t;

  cin>>t;

  while(t--){

    l1 n,l,r;

    cin>>n>>l>>r;

    vector<l1> v(n);

    vector<l1> a(n);

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

      cin>>v[i];

      a[i]=v[i];

    }

    

    l1 sum1=0,sum2=0;

    sort(a.begin(),a.begin()+r);

    sort(v.begin()+l-1,v.end());

    // for(int i=0;i<n;i++) cout<<v[i]<<" ";

    // cout<<endl;

    l1 j=0,p=l-1;

    for(int i=l;i<=r;i++){

       sum1+=a[j++];

       sum2+=v[p++];

      // cout<<sum2<<" ";

    }

   // cout<<sum2<<endl;

    cout<<min(sum1,sum2)<<endl;

}

}



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

#define ll long long

using namespace std;



int main(){

    int t;

    cin>>t;



    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        l--; r--;

        vector<int> arrleft;     //[left, n-1]

        vector<int> arrright;    //[0, right]

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

            int x; cin>>x;

            if(i>=l && i<=n-1) arrleft.push_back(x);

            if(i>=0 && i<=r) arrright.push_back(x);

        }



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

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



        ll total1=0, total2=0;

        for(int i=0; i<r-l+1; i++){

            total1 += arrleft[i];

            total2 += arrright[i];

        }



        cout<<min(total1, total2)<<endl;

    }

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
/* Truong Nhat Nguyen */

#include <bits/stdc++.h>

#define endl '\n'
#define f0(i, n) for (int i = 0; i < n; ++i)
#define f1(i, n) for (int i = 1; i <= n; ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define setpr(x) cout << setprecision(x) << fixed
#define MOD 1000000007
#define ll long long
// #define int long long
const long long INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

using namespace std;

void solve()
{
    int n; cin >> n;
    vector<int>a(n);
    f0(i,n) cin >> a[i];
    f0(i,n-1){
        int min_val = min(a[i],a[i+1]);
        a[i] -= min_val;
        a[i+1] -= min_val;
    }
    f0(i,n-1){
        if(a[i] > a[i+1]){
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TC;
    cin >> TC;
    while (TC--)
    {
        solve();
    }
}

Solution 2 (runtime: 108 ms):
#include <iostream>

#include <vector>

#include <algorithm>



using namespace std;



typedef long long ll;



void processTestCase() {

ll n;

cin >> n;

vector<ll> numbers(n);



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

cin >> numbers[i];

}



ll breakPoint = 0;

for (ll i = 1; i < n; i++) {

if (numbers[i - 1] > numbers[i]) {

breakPoint = i;

}

}



if (breakPoint == 0) {

cout << "YES" << endl;

return;

}



for (ll i = 0; i < breakPoint; i++) {

ll minValue;

if (numbers[i] < numbers[i + 1]) {

minValue = numbers[i];

} else {

minValue = numbers[i + 1];

}

numbers[i] = numbers[i] - minValue;

numbers[i + 1] = numbers[i + 1] - minValue;

}



bool isSorted = true;

for (ll i = 1; i < n; i++) {

if (numbers[i - 1] > numbers[i]) {

isSorted = false;

break;

}

}



if (isSorted) {

cout << "YES" << endl;

} else {

cout << "NO" << endl;

}

}



int main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);



ll testCases;

cin >> testCases;



while (testCases > 0) {

processTestCase();

testCases = testCases - 1;

}



return 0;

}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

typedef long long ll;

#define rep(b) for (ll i = 0; i < b; ++i)

#define f(i, a, b) for (ll i = a; i <= b; ++i)

#define vl vector<ll>

#define vp vector<pair<ll, ll>>

#define ALL(x) (x).begin(), (x).end()

#define eb emplace_back

#define ia(a, n)     \

    vector<ll> a(n); \

    f(i, 0, n - 1) cin >> a[i]



const ll mod = 1e9 + 7;



long long power(long long base, long long exp) {

    long long result = 1;

    

    while (exp > 0) {

        // If exp is odd, multiply the result by base

        if (exp % 2 == 1) {

            result *= base;

        }

        

        // Square the base and halve the exponent

        base *= base;

        exp /= 2;

    }

    

    return result;

}

void solve(){

    int n ;

    cin >> n ;

    string s ;

    cin >> s ;

    int posP = -1;

    int posS = -1;

    if(s[0] == 's')s[0] = '.' ;

    if(s.back() == 'p')s.back() = '.' ;



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

       if(s[i] == 'p')posP = i ;

       if(s[i] == 's')posS = i ;

    }

    if(posS != -1 && posP != -1){

        cout << "NO" << endl;

    }

    else cout << "YES" << endl;



    

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.flush();

    ll t;

    cin >> t;



    while (t--)

    {

        solve();

    }



    return 0;

}



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



using namespace std;



int n;

string s;

void solve() {

    cin >> n >> s;

    

    int l = n - 1, r = 0;

    while(l >= 0 && s[l] != 's') l--;

    while(r < n && s[r] != 'p') r++;

    if(l > r) {

        cout << "No" << '\n';

        return;

    }



    if(l < 1 || n - r < 2) {

        cout << "Yes" << '\n';

    } else {

        // cout << l << ' ' << r << '\n';

        cout << "No" << '\n';

    }

}



int main() {

    int t;  cin >> t;

    while(t--) {

        solve();

    }

    return 0;

}



/*

sspp

4312

*/
Problem: 2050C - Uninteresting Number
Language: c++17 

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

void SetFastIO() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
}

#define For(index,start,end) for(LI index {start} ; index < end ; ++index)
#define Loop(end)            for(LI i {0} ; i < end ; ++i)
#define CFor(i,container)    for(const auto& i : container)
#define RFor(i,container)    for(auto& i : container)
#define F first
#define S second

#define print(container)     for(const auto& x : container)cout << x << ' ';cout << '\n';

using namespace std;
typedef unsigned long long int ULLI;
typedef unsigned long int ULI;
typedef long long int LLI;
typedef long int LI;

void solve(){
    string str;
    cin >> str;
    int cnt2 {};
    int cnt3 {};
    int sum  {};
    
    for(int i {} ; i < str.size() ; i++){
        cnt2 += str.at(i) == '2';
        cnt3 += str.at(i) == '3';
        sum  += str.at(i) - '0';
    }

    sum %= 9;
    vector<int> vec;
    for(int i {} ; i <= min(3,cnt3) ; i++){
        vec.push_back((sum + i * 6) % 9);
    }

    RFor(c,vec){
        for(int i {0} ; i <= min(cnt2,8) ; i++){
            if(c % 9 == 0){
                cout << "YES";
                return;
            }
            c += 2;
        }
        //cout << '\n';
    }
    cout << "NO";
}

int main() {
    int t {1};
    cin >> t;
    for(;t--;cout << '\n')solve();

    return 0;
}

/*   /\_/\
*   (= ._.)
*   / >  \>
*/

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

using namespace std;

int main(){

	int t;

	cin>>t;

	while(t--){

		string n;

		cin>>n;

		int sum=0,cnt2=0,cnt3=0,flag=0;

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

			int x=std::stoi(n.substr(i,1));

			sum+=x;

			if(x==2){

				cnt2++;

			}

			else if(x==3){

				cnt3++;

			}

		}

		sum%=9;

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

			for(int j=0;j<=min(10,cnt3);j++){

				if((sum+i*2+j*6)%9==0&&flag==0){

					cout<<"YES"<<endl;

					flag++;

					break;

				}

			}

		}

		if(flag==0){

			cout<<"No"<<endl;

		}

	}

	return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

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

#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize("O3,unroll-loops")

#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

using namespace __gnu_pbds;

typedef long long ll;

typedef unsigned long long ull;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define endl "\n"

#define DBG(x) cerr << #x << " = " << x << endl;

#define LINE cerr << "====================" << endl;

#define forn(n) for(ll i = 0; i < n; i++)

#define forin(a, n) for(ll i = a; i < n; i++)

#define mostrar(v) if(true) { for(auto &it : v) cout << it << " "; cout << endl; }

#define pb push_back

#define all(v) v.begin(), v.end()

#define fastio ios::sync_with_stdio(false); cin.tie(0);

const ll INF = 1e18;



void solve(vector<ll>&v, ll l, ll r){

    ll n = v.size();

    vector<ll>left, right;

    for(ll i=0; i<r; i++) left.pb(v[i]);

    for(ll i=l-1; i<n; i++) right.pb(v[i]);

    sort(all(left));

    sort(all(right));

    ll sumL, sumR; sumL = sumR = 0;

    ll rango = r-l+1;

    for(ll i=0; i<rango; i++){

        if(i < left.size()) sumL += left[i];

        if(i < right.size()) sumR += right[i];

    }

   // cout << sumL << " " << sumR << endl;

    ll ans = min(sumL, sumR);

    cout << ans << endl;

}



int main() {

    fastio;

    ll t; cin >> t;

    while(t--){

        ll n, l, r; cin >> n >> l >> r;

        vector<ll>v(n);

        for(auto &it:v) cin >> it;

        solve(v, l, r);

    }   

    return 0;

}

Solution 2 (runtime: 124 ms):
/* परिवर्तिनि संसारे मृतः को वा न जायते |
   स  जातो येन जातेन याति वंश समुन्नतिम्||  */
   
#include<bits/stdc++.h>
#define Fastio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long double lld;
typedef unsigned long long ull;
typedef long long ll;

constexpr int MOD=1e9+7;

#ifdef ARPIT
#include "karpit.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif


signed main() {
Fastio
#ifdef ARPIT
    freopen("error.txt", "w", stderr);
#endif
    int t  = 1;
    cin>>t; 
    // Solve Here 
    while(t--){
      ll n,l,r;
      cin>>n>>l>>r;
      vector<ll> a(n),left,right,mid;
      for(int i=0;i<n;i++){
        cin>>a[i];
        if(i<l-1)left.push_back(a[i]);
        else if(i>=l-1&&i<=r-1)mid.push_back(a[i]);
        else right.push_back(a[i]);
      }
      sort(left.begin(),left.end());
      sort(mid.rbegin(),mid.rend());
      sort(right.begin(),right.end());

      int i=0;
      ll sum1=0;
      while(i<mid.size()){
        if(i<left.size()) sum1+=min(mid[i],left[i]);
        else sum1+=mid[i];
        i++;
      }
      i=0;
      ll sum2=0;
      while(i<mid.size()){
        if(i<right.size()) sum2+=min(mid[i],right[i]);
        else sum2+=mid[i];
        i++;
      }

      cout<<min(sum1,sum2)<<"\n";
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <iostream>
#include <algorithm>

using namespace std;

int SOD(string n){
    int sum = 0;
    for(int i = 0; i<n.size(); i++){
        sum += n[i] - 48;
    }
    return sum;
}

int main(){
    int t;
    cin>>t;
    while(t--){
            string n;
    cin>>n;
    int x = count(n.begin(), n.end(), '2');
    int y = count(n.begin(), n.end(), '3');
    int flag = 0;
    for(int i=0; i<=min(8, x); i++){
        for(int j=0; j<=min(8, y); j++){
            if((SOD(n) + i*2 + j*6) % 9 == 0){
                flag = 1;
                break;
            }
        }
    }

    if(flag)
        cout<<"YES\n";
    else
        cout<<"NO\n";

    }
}

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

using namespace std;

#define int long long

#define endl '\n'

#define mod 1000000007



void solve() {

    string s;

    cin >> s;

        int cnt2=0,cnt3=0,sum=0;

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

            sum += s[i] - '0';

            if (s[i] == '2')++cnt2;

            else if (s[i] == '3')++cnt3;

        }



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

        for(int j=0;j<=cnt3;j++){

            if((sum + i*2 + j*6)%9==0){

                cout<<"YES"<<endl;

                return;

            }

        }

    }



    cout<<"NO"<<endl;

}





int32_t main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    // int num=1;

    // while(num<100){

    //     s.insert(num*num);

    //     num+=2;

    // }



    int t;

    cin >> t;

    while (t--) 

        solve();



    return 0;

}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	if(s[0]=='s') s[0]= '.';

	if(s[n-1]=='p') s[n-1]='.';

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		cout<<"NO\n";

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

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

using namespace std;





   void solve(){

      int n;

      cin>>n;

      string s;

      cin>>s;

      int pp=0;

      int ss=0;

      

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

         if(s[i]=='p'){

            pp++;

         }else if(s[i]=='s'){

            ss++;



        

        

      }

   }

     

      if(ss==0||pp==0){

         cout<<"YES"<<endl;

         return ;

      }

      int s1=0;

      int p1=-1;

      int idx=0;

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

         if(s[i]=='s'){

            s1=idx;

         }

         if(s[i]=='p'){

            if(p1==-1){

               p1=idx;

            }

         }

         idx++;

      }

      if(s1==0||p1==n-1){

         cout<<"YES"<<endl;

         return;

      }





        

      cout<<"NO"<<endl;

   }





   int main(){

   int t;

   cin>>t;



   while(t--){

      solve();



   }



return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<iostream>
#include<map>
#include<unordered_map>
#include<vector>
 
#define ll long long 
#define mp make_pair
#define d double
 
using namespace std;
 
void f(vector<ll> &v,ll &n){
   for(ll i = 0;i<n;i++){
       cin>>v[i];
   }
}
 
int main(){
    ll t;
    cin>>t;
 
    while(t--){
       ll n;
       string s;
       cin>>s;
       n = s.length();
       vector<int> dig(n);
     
       for(ll i=0;i<n;i++){
           dig[i] = s[i]-'0';
       }
       
       for(ll i=1;i<n;i++){
           ll curr = i;
           while(curr>=1 && dig[curr]-1>dig[curr-1]){
               int frwd = dig[curr]-1;
               dig[curr] = dig[curr-1];
               dig[curr-1] = frwd;
               curr--;
           }
       }
       
       for(auto it : dig) cout<<it;
       cout<<endl;
    }
}

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

using namespace std;

#define ll long long

int main(){

  ll t;

  cin>>t;

  while(t--){

    string s;

    cin>>s;

    ll n=s.length();

    ll a[n];

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

      a[i]=s[i]-'0';

    }

    for(ll i=1;i<n;i++){

      for(ll j=i;j>0;j--){

        if(a[j-1]+1>=a[j]) break;

        else{

          ll temp=a[j-1];

          a[j-1]=a[j]-1;

          a[j]=temp;

        }

      }

    }

    for(ll i=0;i<n;i++) cout<<a[i];

    cout<<endl;

  }

  return 0;

}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl '\n'
#define No cout<<"NO"<<endl
#define Yes cout<<"YES"<<endl
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void omaer()
{
  int n;
  cin>>n;

  ll o=0, e=0;
  for(int i=0;i<n;i++)
  {
    int a;
    cin>>a;

    if(i%2==0) e+=a;
    else o+=a;
  }

  ll od=n/2, ev=n/2;
  if(n&1) ev+=1;

  if(o%od!=0 || e%ev!=0 || o/od != e/ev) No;
  else Yes;
}

int main()
{
    optimize();

    int t;
    cin>>t;
    while(t--)
    {
        omaer();
    }

	return 0;
}


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

using namespace std;

int main(){

	int t;

	scanf("%d",&t);

	int n;

	vector<int>a(n);

	while(t--){

		

		scanf("%d",&n);

		long long int sum_ji=0,cnt_ji=0,sum_ou=0,cnt_ou=0;

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

			scanf("%d",&a[i]);

			if(i==0||i%2==0){

				sum_ji+=a[i];

				cnt_ji++;

			}else{

				sum_ou+=a[i];

				cnt_ou++;

			}

		}

		

		int equal=(sum_ji+sum_ou)/n;

		

		if(cnt_ji*equal!=sum_ji){

			printf("NO\n");

			continue;

		}

		if(cnt_ou*equal!=sum_ou){

			printf("NO\n");

			continue;

		}

		printf("YES\n");

		

		

	}

	return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while(t--)
    {
        string n;
        cin >> n;
        int twocount  = 0;
        int threecount = 0;
        ll sum = 0;
        bool flag = false;
        for(int i =0; i < n.size(); i++)
        {
            if(n[i] == '2')
            twocount++;
            else if(n[i] == '3')
            threecount++;
            sum += n[i] - '0';
        }
        for(int i = 0 ; i < min(10, twocount+1); i++)
        {
            for(int j = 0; j < min(10,threecount+1); j++)
            {
                if((sum + 2 * i + 6 * j) % 9 == 0)
                {
                    flag = true;
                }
            }
        }
        if(flag)
        cout << "YES" << endl;
        else
        cout << "NO" << endl;

    }
}

Solution 2 (runtime: 61 ms):
#include <iostream>
using namespace std;

/*
Remainder   Difference
1  +8
2  +16
3  +6
4  +14                      
5  +4
6  +12
7  +2
8  +10
*/

int rm[9] = {0, 8, 16, 6, 14, 4, 12, 2, 10};
bool can23 (int n2, int n3, int r) {
    n2 *= 2;
    n3 *= 6;
    if (r <= n2) return true;
    if (r == n3) return true;
    if (r > n3) {
        r -= n3;
        if (r <= n2) return true;
        else return false;
    }
    else {
        r = r % 6;
        if (r <= n2) return true;
        else return false;
    }
}
int main () {
    int T;
    cin >> T;
    cin.ignore();
    while (T--) {
        string number;
        cin >> number;
        cin.ignore();
        int cnt[4] = {0,0,0,0};
        int sum = 0;
        for (int i=0; i<number.length(); i++) {
            sum += number[i]-'0';
            if (number[i]>'1' && number[i] <= '3') {
                cnt[number[i]-'0']++;
            }
        }
        if (sum % 9 == 0) {
            cout << "YES" << endl;
            continue;
        }
        if (can23(cnt[2], cnt[3], rm[sum % 9]))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 343 ms):
#include<iostream>
#include<vector>
using namespace std;

int main(){
  int t;
  cin>>t;
  while (t--)
  {
    int n;
    cin>>n;
    vector<int>v(n);
    for (int i = 0; i <n; i++)
    {
      
      cin>>v[i];
    }
   
   long long evensum=0;
   long long even=0,oddsum=0,odd=0;
   for (int i = 0; i <n; i++)
   {
      if (i%2==0)
       {
          evensum+=v[i];
          even++;
       }
       else{
         oddsum+=v[i];
         odd++;
       }   
   }

   if (evensum%even==0 && oddsum%odd==0)
   {
       if (evensum/even==oddsum/odd)
       {
          cout<<"YES"<<endl;
       }
       else{cout<<"NO"<<endl;}
       
   }
   else{cout<<"NO"<<endl;}
   
  }
}

Solution 2 (runtime: 93 ms):
#include<iostream>

#include<bits/stdc++.h>

using namespace std;







int main()

   

{

    int t;

    cin >> t;

    while(t--){

        int n;

        cin >> n;

        vector<int> arr(n);

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

        cin >> arr[i];



        int od = 0;

        int ev = 0; 

        long long int od_sum = 0;

        long long int ev_sum = 0;



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

            od++;

            od_sum+=arr[i];

        }

        for (int i = 1; i<n ; i+=2){

            ev++;

            ev_sum+=arr[i];

        }



        if (od_sum%od==0 && ev_sum%ev==0 && od_sum/od == ev_sum/ev)

        cout << "YES" << endl;

        else 

        cout << "NO" << endl;

    }

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

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

using namespace std;
const int N = 100950;
int a[N];
map<int,int> mp;
vector<int> v;
int main(){
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            mp[a[i]]++;
        }
        for(auto it:mp)
            v.push_back(it.second);
        sort(v.begin(),v.end());
//        for(auto it:v)
//            cout<<it<<" ";
//        cout<<endl;
        int ans = v.size();
        for(auto it:v){
            if(k>=it)
                k -= it,ans--;
            else
                break;
        }
        if(ans==0) ans = 1;
        cout<<ans<<endl;
        v.clear();
        mp.clear();
    }
}

Solution 2 (runtime: 327 ms):
#include <bits/stdc++.h>
using namespace std;

int main(){
  
int t;
cin>>t;
while(t--){
      int n,k;
      cin >> n>> k;
      map<long long, int> mp;
      set<long long> v; 
      vector <int> cnt;
      for(int i = 0;i<n;i++){
            long long x;  
            cin>>x;
            v.insert(x);
            mp[x]++;    
      }
      auto it = v.begin();
      for(int i = 0;i<mp.size();i++){
            cnt.push_back(mp[*it]);
            it++;
            }
      sort(cnt.begin(),cnt.end());      
      
      for (int  i = 0; i < cnt.size(); i++)
      {
           if(k>0){
               int x = cnt[i];
               if(k>=x){
                   k = k - x;
                   cnt[i] = 0;
               cnt[cnt.size()-1] = cnt[cnt.size()-1] + x;
                  
               }
                  else{
                         cnt[cnt.size()-1] = cnt[cnt.size()-1] + k;
                              cnt[i] -= k;
                              k = 0;
                  }
              
           }
      }
      int ans =0;
      for(int i = 0;i<cnt.size();i++){
            if(cnt[i]!=0){
                  ans++;
            }
      }
      cout<<ans<<endl;
}

}