ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: c++17 

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

int main() {
    long long t;
    cin >> t;
    while (t--) {  
        long long n, x;
        cin >> n; 
        vector<long long> v;

        for (long long i = 0; i < n; i++) {
            cin >> x;
            v.push_back(x);
        }

        long long loop = 0;
        long long sum;
        if (v.size() > 1) {
            sum = accumulate(v.begin(), v.end(), 0LL); // Use 0LL to indicate long long initial value
        } else {
            sum = v[0];
        }

        while (v.size() - 1) {
            for (size_t i = v.size() - 1; i > 0; i--) {
                v[i] = v[i] - v[i - 1]; // Update current index with difference
            }

            v.erase(v.begin());
            if (abs(accumulate(v.begin(), v.end(), 0LL)) > sum) {
                sum = abs(accumulate(v.begin(), v.end(), 0LL));
            }
        }
        
        cout << sum << endl;
    }

    return 0;
}


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

int main() {
    int t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        long long arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];}
        if(n==1){
            cout<<arr[0]<<endl;
            continue;
        }
        long long sum=0,ma=INT_MIN;
        for(int i=0;i<n;i++){
            sum+=arr[i];
        }
        long long f=abs((arr[n-1]-arr[0]));
        ma=max(f,ma);
        for(int i=1;i<=(n-1);i++){
            for(int j=0;j<(n-i);j++){
            arr[j]=(arr[j+1]-arr[j]);}
            long long k;
            if(i!=(n-1)){
                k=abs(arr[0]-arr[n-i-1]);
            }
            else{
                k=abs(arr[0]);
            }
            ma=max(k,ma);
        }
        ma=max(ma,sum);
        cout<<ma<<endl;
    }

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

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

using namespace std;

#define int long long int

signed main(){

    int t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        int a[n],b[n];

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

            cin>>a[i];

            b[i]=a[i];

        }

        int g=r-l+1;

        sort(a,a+r,greater<int>());

        sort(b+l-1,b+n);

        int h=accumulate(a+l-1,a+r,0LL);

        int f=accumulate(b+l-1,b+r,0LL);

        cout<<min(f,h)<<endl;

    }

}

Solution 2 (runtime: 218 ms):
#include "bits/stdc++.h"



using namespace std; 

#define int long long



signed main() 

{ 

	int test;

	cin>>test;



	while(test--){

		int n,a,b, ans = 0, maxi = 0;

		string s;

		cin>>n>>a>>b;

		int num = (b - a + 1);

		std::vector<int> v(n,0);

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

		{

			cin>>v[i];

		}

		vector<int> temp1,temp2;

		for (int i = a-1; i < n; ++i)

		{

			temp1.push_back(v[i]);

		}

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

		{

			temp2.push_back(v[i]);

		}

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

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

		int ans1 =0 , ans2 = 0;

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

		{

			ans1+= temp1[i];

			ans2+= temp2[i];

		}

		cout<<min(ans1, ans2)<<endl;

	}

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

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


int main() {
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int N2=0,N3=0;
        int sum=0;
        for(auto c:n){
            int d=c-'0';
            if(d==2) N2++;
            if(d==3) N3++;
            sum=(sum+d)%9;
        }
        int n2=min(8,N2);
        int n3=min(8,N3);
        string ans="No";
        for(int i=0;i<=n2;i++){
            for(int j=0;j<=n3;j++){
                int r=(2*i+6*j)%9;
                if(r==(9-sum)%9){
                    ans="Yes";
                    break;
                }
            }
            if(ans=="Yes") break;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

const int N = 10010;
int f[10];
int t;
string s;

// bool dfs(int i,int j) {
//     if(f[i][j] != -1) return f[i][j];
//     bool ok;
//     if(i == s.size()) ok = j == 0;
//     else if(s[i] >= '4') ok = dfs(i+1,j + s[i] - '0');
//     else {
//         int path = s[i] - '0';
//         ok = dfs(i+1,(j + s[i] - '0') % 9) || dfs(i+1,(j + path * path) % 9);
//     }
//     f[i][j] = ok;
//     return f[i][j];
// }

int main() {
    cin >> t;
    while(t--) {
        cin >> s;
        int t2 = 0,t3 = 0;
        int sum = 0;
        bool ok = false;
        for(auto c : s) {
            sum += c - '0';
            if(c == '2') t2++;
            if(c == '3') t3 ++;
        }
        for(int i = 0; i<=t2 && i <= 8 && !ok; i++) {
            for(int j = 0; j<=t3 && j <= 8 && !ok; j++) {
                int t = sum + i * 2 + j * 6;
                if(t % 9 == 0) {
                    cout << "YES" << endl;
                    ok = true;
                }
            }
        }
        if(!ok) cout << "NO" << endl;
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 171 ms):
#include <algorithm>
#include <array>
#include <iostream>
#include <queue>
#include <set>
#include <cstdint>
#include <string>
#include <vector>

using namespace std;

void solve() {
    // Read input
    int n, m;
    cin >> n >> m;
    priority_queue<int> a;
    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        a.push(val);
    }

    priority_queue<int> b;

    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        b.push(val);
    }

    
    while (!b.empty() && !a.empty()) {
        // cout << a.top() << " " << b.top() << endl;
        if (a.top() > b.top() || a.size() < b.size()) {
            cout << "No\n";
            return ;    
        }
        if (a.top() == b.top()) {
            a.pop(); b.pop();
            continue;
        }
        int c = b.top();
        b.pop();
        int c1 = c / 2;
        int c2 = (c + 1) / 2;
        b.push(c1);
        b.push(c2);
    }
    // Print output
    if (a.empty() && b.empty()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

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

    return 0;
}

Solution 2 (runtime: 640 ms):
#include<iostream>
#include<queue>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		priority_queue<int> q;
		priority_queue<int> Q;	
		int n,m;
		cin>>n>>m;
		for(int i=0;i<n;i++){
			int a;
			cin>>a;
			q.push(a);	
		}
		for(int i=0;i<m;i++){
			int b;
			cin>>b;
			Q.push(b);
		}
		while(1){
			if(m>n){
				cout<<"No"<<'\n';
				break;
			}
			if(Q.empty() and !q.empty()){
				cout<<"No"<<'\n';
				break;
			}
			if(q.empty() and Q.empty()){
				cout<<"Yes"<<'\n';
				break;
			}
			int a = q.top();
			int b = Q.top();
			//cout<<a<<' '<<b<<'\n';
			if(a==b){
				q.pop();
				Q.pop();
				n--;
				m--;
			}
			if(b>a){
				Q.pop();
				Q.push(b/2);
				Q.push(b-b/2);
				m--;
				m+=2;
			}
			if(b<a){
				cout<<"No"<<'\n';
				break;
			}
		}
	}
}
Problem: 2050D - Digital string maximization
Language: c++17 

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


void solve(){
    string s; cin >> s;
    int n = s.length();
    s = '$' + s;
    for(int i = 1; i <= n; i++){
        pair<char, int>mx = {0, 0};
        for(int j = i; j <= min(n, i + 9LL); j++){
            if(mx.first < s[j] - (j - i)) mx = { s[j] - (j - i), j};
        }
        if(mx.second != i){
            for(int j = mx.second; j > i; j--) s[j]--, swap(s[j], s[j-1]);
        }
    }
    for(int i = 1; i <= n; i++) cout << s[i];
    cout << '\n';
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while(t--)
    solve();
}

Solution 2 (runtime: 140 ms):
#include<bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pi pair<ll,ll>
#define F first
#define S second
#define dbg(x) cout <<#x<<": "<<x<< '\n';
template<typename T>
void watch(vector<T>&v){for(auto&x:v)cout<<x<<" ";cout<<'\n';}
void io(){ios::sync_with_stdio(false);cin.tie(NULL);}
#define all(x) (x).begin(), (x).end()
const ll INF = 0x3f3f3f3f3f3f3f3fLL;

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; }
template <class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template <class T>
bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
const ll N = 2e5 + 100;

void solve() {
    string s;cin >> s;
    int n = s.size();
    for(int i = 0 ; i < n ; i ++){
        ll idx = i , x = 1;
        int k = s[i] - '0';char p = s[i];
        for(int j = i - 1 ; j >= max(i - 9ll , 0ll) ; j -- ){
            if((k - x) > (int)s[j] - '0'){
                p = (k - x) + '0';
                idx = j;
            }
            x ++ ;
        }
        vector <char> a = {p};
        int ii = 0;
        for(int j = idx ; j <= i - 1 ; j ++) a.pb(s[j]);
        for(int j = idx ; j <= i ; j ++) s[j] = a[ii ++ ];
        
    }
    cout << s << '\n';
}



signed main() {
    #ifndef ONLINE_JUDGE
       freopen("input.in", "r", stdin);
       freopen("output.out", "w", stdout);
    #endif // ONLINE_JUDGE
    io();
    int T = 1; 
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

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

#define ll long long 
#define vi vector<int>
#define vll vector<ll>
#define pyes cout << "YES" << endl;
#define pno cout << "NO" << endl;
#define f(i, a, b) for(ll i = a; i < b; i++)
#define fe(i, a, b) for(ll i = a; i <= b; i++)

void solve() {
    int n;
    cin>>n;
    ll od=0,ev=0;
    ll nd=0,ne=0;
    f(i,0,n){
        if(i%2==0){
            int s;
            cin>>s;
            ne++;
            ev+=s;
        }
        if(i%2==1){
            int s;
            cin>>s;
            nd++;
            od+=s;
        }
    }
    if(ev%ne!=0){
        pno;
        return;
    }
    if(od%nd!=0){
        pno;
        return;
    }
    if(ev/ne==od/nd){
        pyes;
        return;
    }else{
        pno;
    }
}

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

Solution 2 (runtime: 343 ms):
#include<bits/stdc++.h>
using namespace std;
 
void init_code() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}


// 1
// 2
// 2
// 1
// 0

 
 
void solver(){
 long long n;
 cin>>n;
 vector<long long>mack(n);
 for(int i = 0 ;i<n;i++){
 	cin>>mack[i];
 }
 long long countEven = 0;
 long long countOdd = 0;
 long long sumEven = 0;
 long long sumOdd = 0;
 for(int i = 0 ;i<n ; i++){
 	if(i%2==0){
 		countEven++;
 		sumEven+=mack[i];
 	}
 	else{
 		countOdd++;
 		sumOdd += mack[i];
 	}
 }
 // sum1/count1 == sum2/count2
 if((countOdd*sumEven == countEven*sumOdd) &&(sumOdd+sumEven)%(n)==0){
 	cout<<"YES"<<endl;
 }
 else{
 	cout<<"NO"<<endl;
 }
}
 
 
int main() {
    
    init_code(); 
    int t;
    cin>>t;
    while(t--){
        solver();
    }
    
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

int main() {
    int n;cin>>n;
    vector<int> arr(n);
    vector<int> temp;
    set<int> st;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        st.insert(arr[i]);
    }
    vector<pair<int,int> > ans;
    for(int i=0;i<n;i++){
        auto itr = st.upper_bound(arr[i]);
        while(itr != st.end()) ans.push_back({*itr,arr[i]}), itr++;
        st.erase(arr[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans.push_back({arr[i],arr[j]});
        }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++) cout<<ans[i].first<<" "<<ans[i].second<<endl;
}


Solution 2 (runtime: 1311 ms):
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int order[1005];
bool visit[1005];

struct mypair{
    int x, y;
};

int main()
{
    int n;
    cin >> n;
    vector<mypair> vec;
    for(int i = 1; i <= n; i++) {
        cin >> order[i];
    }
    for(int i = n; i >= 1; i--) {
        for(int j = order[i] - 1; j >= 1; j--) {
            if(!visit[j]) {
                vec.push_back({order[i], j});
            }
        }
        for(int j = 1; j <= order[i] - 1; j++) {
            if(!visit[j]) {
                vec.push_back({j, order[i]});
            }
        }

        for(int j = order[i] + 1; j <= n; j++) {
            if(!visit[j]) {
               vec.push_back({j, order[i]});
            }
        }
        visit[order[i]] = true;
    }
    cout << vec.size() << endl;
    for(int i = 0; i < vec.size(); i++) {
            mypair mp = vec[i];
        cout << mp.x << " " << mp.y << endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 562 ms):
#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;
}

Solution 2 (runtime: 93 ms):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

using ll = long long;

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

    int cases;

    std::cin >> cases;
    
    for (int i = 0; i < cases; i++) {
        ll n, k;
        std::cin >> n >> k;

        std::vector<int> v(n, 0);
        for (ll j = 0; j < n; j++) {
            std::cin >> v[j];
        }

        sort(v.begin(), v.end());
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > p;
        map<int, int> m;

        ll numUnique = 0;
        for (ll j = 0; j < v.size(); j++) {
            m[v[j]]++;
        }

        for (auto it = m.begin(); it != m.end(); it++) {
            numUnique++;
            p.push(make_pair(it->second, it->first));
        }

        while (k--) {
            pair<int, int> temp = p.top();
            temp.first--;
            p.pop();
            if (temp.first == 0) {
                numUnique--;
            }
            else {
                p.push(temp);
            }

            if (numUnique <= 1) {
                break;
            }
        }

        if (numUnique < 1) {
            numUnique = 1;
        }
        std::cout << numUnique << std::endl;
    }

    return 0;
}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

using ll =long long;



int main ()

{

	int t; cin >> t;

	while(t --)

	{

		int n, i; cin >> n;

		string s; cin >> s;

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

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

		int flag = 0; bool ans = true;

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

		{

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

				continue;

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

			{

				if(flag == 0)

					flag = 1;

				else if(flag == 1)

					continue;

				else

				{

					ans = false;

					break;

				}

			}

			else

			{

				if(flag == 0)

					flag = 2;

				else if(flag == 2)

					continue;

				else

				{

					ans = false;

					break;

				}				

			}

		}

		if(ans) cout << "YES\n";

		else cout << "NO\n";

	}

	return 0;

}

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

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code();

#include<bits/stdc++.h>

#define ll long long 

#define read(x) int x;cin>>x;

#define vi vector<int>

#define vvi vector<vi>

#define vl vector<ll>

#define vvl vector<vl>

#define vb vector<bool>

#define ld long double 

using namespace std;



void init_code(){

	#ifndef ONLINE_JUDGE

	freopen("inputf.txt","r",stdin);

	freopen("outputf.txt","w",stdout);

	#endif

}



ll min(ll a, ll b){

	if (a<b)return a;

	return b;

}



ll max(ll a, ll b){

	if (a>b)return a;

	return b;

}



void print(vi &arr){

	for (auto i:arr)cout <<i<<" ";

	cout <<endl;

}



void solve(){

	int n; cin >> n;

    string s; cin >> s;

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

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

    bool found_p = false;

    bool found_s = false;

    for (const auto c : s)

    {

        switch (c)

        {

        case 'p':

            found_p = true;

            break;

        case 's':

            found_s = true;

            break;

        }

    }

    cout << (found_p && found_s ? "NO" : "YES") << '\n';

}



int main(){

	fast ;

	read(t);

	while (t--)solve();

	return 0;

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

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define endl "\n"
#define pb push_back

ll mod = 1e9 + 7;

//vector<vector<pair<int, int>>> vec;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1, ct=0, flag=1;
    cin>>t;
    while (t--) {
        string s;cin>>s;
        ll tot=0, cnt2=0, cnt3=0, fl=0;
        for(ll i=0;i<s.size();i++){
        	tot+=s[i]-'0';
        	if(s[i]=='2') cnt2++;
        	if(s[i]=='3') cnt3++;
        }
        for(ll i=0;i<min((ll)10, cnt2+1);i++){
        	for (int j = 0;  j < min((ll)10, cnt3+1); j++){
        		ll a = tot + 2*i + 6*j;
        		//cout<<i<<" "<<j<<" "<<a<<" "<<tot<<endl;
        		if(a%9 == 0){
        			fl = 1;
        			break;
        		}
        	}
        	if(fl) break;
        }
        if(fl) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}


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

using namespace std;

#define ll long long

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

const ll N = 1e5+5, mod = 1e9 + 7;

int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };

int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };

char di[] = { 'R', 'L', 'D', 'U' };

void solve() {

    int sum = 0, n2 = 0, n3 = 0;

    string s; cin >> s;

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

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

        n2 += (s[i] == '2');

        n3 += (s[i] == '3');

    }

    bool f = 0;

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

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

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

                f = 1; break;

            }

        }

    }

    cout << (f ? "YES\n" : "NO\n");

}

int main() {

    // freopen("qual.in", "r", stdin);

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int tc = 1; cin >> tc;

    while (tc--) {

        solve();

    }

    return 0;

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

Solution 1 (runtime: 202 ms):
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>b(n),cnt;
    for(int i=0;i<n;i++)cin>>b[i];
    sort(b.begin(),b.end());
    cnt.push_back(1);
    for(int i=1;i<n;i++){
        if(b[i]==b[i-1]){
            cnt.back()++;
        }else{
            cnt.push_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    int nn=cnt.size();
    for(int i=0;i<nn-1;i++){
        if(cnt[i]>k){
             cout<<nn-i<<endl;
             return;
        } 
        k-=cnt[i];
    }
    cout<<1<<endl;
    return;
}
signed main(){
    int t;cin>>t;
    while(t--)solve();
    return 0;
}

Solution 2 (runtime: 218 ms):
#include <bits/stdc++.h>
#include <stack>
#include <string>
#define int long long
#define double long double
#define endl '\n'
#define Endl '\n'
using namespace std;
int num[500050];
int A[500050];
signed main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n,k;
		cin >> n >> k;
		for(int i=1;i<=n;i++)
		{
			cin >> A[i];
		}
		sort(A+1,A+1+n);
		int cnt=0;
		int op=1;
		for(int i=1;i<=n;i++)
		{
			if(A[i]==A[i+1])
			{
				op++;
			}else {
				num[++cnt]=op;
				op=1;
			}
		}
		sort(num+1,num+1+cnt);
		int sum=0;
		for(int i=1;i<=cnt;i++)
		{
			if(num[i]<=k)
			{
				k-=num[i]; 
			}else {
				sum++;
			}
		}
		cout << max((int)1,sum) << endl;
		for(int i=0;i<=n;i++)
		{
			A[i]=0;num[i]=0;
		}
	}
	
	
	return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

int main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int n = s.length();

        for(int i=1;i<n;i++){
            for(int j=max(0,i-s[i]+'0');j<i;j++){
                if(s[j]<s[i]-(i-j)){
                    s[i] = s[i]-(i-j);
                    for(int k=i;k>j;k--){
                        swap(s[k],s[k-1]);
                    }
                    break;
                }
            }
        }

        cout<<s<<endl;

    }

    return 0;
}

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

using namespace std;

#define int long long 

#define PII pair<int,int>

const int N = 2e5 + 10;

int arr[N];



void solve()

{

	string str;cin >> str;

	int n = str.length();

	for (int i = 0;i < n;i++)arr[i] = str[i] - '0';

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

	{

		int m = -1, idx = 0, res = -1;

		int en = min(n, i + 10);

		for (int j = i;j < en;j++)

		{

			res = arr[j] - (j - i);

			if (res > m)

			{

				idx = j;

				m = res;

			}

		}

		if (m != -1 && idx > i)

		{

			for (int j = idx;j >= i + 1;j--)arr[j] = arr[j - 1];

			arr[i] = m;

		}

	}

	for (int i = 0;i < n;i++)cout << arr[i];

	return;

}



signed main()

{

	cin.tie(0), cout.tie(0);

	ios::sync_with_stdio(false);

	int t = 1;

	cin >> t;

	while (t--)

	{

		solve();

		cout << endl;

	}

}