ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

void test() {
    int l, r;
    cin>>l>>r;
    // int a = 0, b = 0, c = 0;
    int prev = 0;
    
    for (int i=30; i>=0; i--) {
        int x = 1<<i;
        if ((x&l)!=(r&x)) {
            int a = x+prev;
            int b = x-1+prev;
            while(true) {
                if (r!=a && r!=b) {
                    cout<<a<<" "<<b<<" "<<r<<endl;
                    return;
                }
                r--;
            }
        } else if (x&l) {
            prev+=x;
        }
    }
    return;

    
    
    
}


int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);
    #endif

    int t=1;
    cin>>t;
    // calc();
    while(t--) {
        test();
    }
    #ifdef ONLINEJUDGE
    fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC); // this line gives your code runtime
    #endif
    return 0;
}

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

using namespace std;
typedef long long ll;

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

    ll t, l, r;
    cin >> t;
    while (t--) {
        cin >> l >> r;

        ll x, z;
        int f = -1;
        for (int i=32;i>=0;i--) {
            if (f == -1 and ((r>>i)&1))
                f = i;
            if (((l>>i)&1) != ((r>>i)&1)) {
                x = (r>>i);
                x <<= i;
                // x = ((1<<(f-i+1))-1)<<i;
                break;
            }
        }
        for (int i=l;i<=r;++i) {
            if (i != x-1 and i != x) {
                z = i;
                break;
            }
        }
        cout << x << " " << x-1 << " " << z << "\n";
    }
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size() && j < 10; j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

        for (int j = i + q; j > i; j--)
            swap(s[j], s[j - 1]);

        s[i] -= q;
    }

    cout << s << "\n";
}

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

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

    return 0;
}


Solution 2 (runtime: 124 ms):
#include<iostream>
#define int long long
using namespace std;
const int N=2e5+5;
int t,n,a[N];
string s;
signed main()
{
    cin>>t;
    while(t--){
        cin>>s;
        n=s.size();
        for(int i=0;i<n;i++){
            int mx=s[i]-'0';
            for(int j=1;j<9&&i+j<n;j++)
                if(s[i+j]-'0'-j>mx)
                    mx=s[i+j]-'0'-j;
            if(mx==s[i]-'0') continue;
            for(int j=1;j<9&&i+j<n;j++)
                if(s[i+j]-'0'-j==mx){
                    char tmp=s[i+j];
                    for(int k=i+j;k>i;k--)
                        s[k]=s[k-1];
                    s[i]=tmp-j;
                    break;
                }
        }
        cout<<s<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <iostream>
#include<iomanip>
#include<climits>
// INT_MAX LLONG_MAX
#include <vector>
#include<array>
#include<queue>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<cmath>
#include <algorithm>
#include<functional>
// function<type(type,type)> func_name;
using namespace std;
#define endl "\n"
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define rfor(i,a,b) for(int i=(a);i>=(b);i--)
#define fios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define dbg cout<<">>>>"<<endl;
using vi=vector<int>;
using vvi=vector<vector<int>>;
template<size_t N>
using ai = array<int, N>;
using pii=pair<int,int>;
typedef long long LL;
const int inf=1e18;
const int CJR=998244353;
const int HY_Spark=1e9+7;

// 可以逆转序列
// 可以用差序替换序列 减少一个元素

// 求运算后 元素和最大值

// a b c ---> b-a c-b 如果为正 显然不对

// 发现前面的数是被减数 则目的是 让负数在前面？ 

// 负数在前面后 进行操作即对元素加上这个数 

// -2 -3 -> 1
// 1 -2 re->det

// -2 1 det

// 1 -2 3 -> -3 5 -> 8
// 3 -2 1 -> -5 3 -> 8


// x y z w
// y-x z-y w-z
// w z y x
// z-w y-z x-y
void solve(){
	int n;
	cin>>n;
	vi a(n+1);
	int ans=0;
	ffor(i,1,n){
		cin>>a[i];
		ans+=a[i];
	}
	
	if(n==1){
		cout<<a[1]<<endl;
		return;
	}
	ffor(i,1,n-1){
		int tmp=0;
		ffor(j,1,n-i){
			a[j]=a[j+1]-a[j];
			tmp+=a[j];
		}
		ans=max(ans,abs(tmp));
		
	}
	cout<<ans<<endl;
}


signed main(){
    fios;
    int _=1;
    cin>>_;
    while(_--){
        solve();
    }
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 50+5;
ll T,n,a[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(nullptr);
	cin>>T;
	while(T--){
		cin>>n;
		ll sum=0,maxx=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			sum+=a[i];
		}
		maxx=sum;
		for(int i=2;i<=n;i++){
			sum=0;
			for(int j=n;j>=i;j--){
				a[j]=a[j]-a[j-1];
				sum+=a[j];
			}
			maxx=max(maxx,(sum<0 ? -sum : sum));
		}
		cout<<maxx<<endl;
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 281 ms):
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define forloop(x,y) for(int i=x;i<y;i++)
#define secondfor(x,y) for(int j=x;j<y;j++)
#define print(x) cout << x << "\n";
#define output(arr) for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
#define asort(v) sort(v.begin(), v.end())
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define intmax INT_MAX
#define intmin INT_MIN
#define lintmax LLONG_MAX
#define lintmin LLONG_MIN
#define mp(x,y) make_pair(x,y)
lint solvefunction(vector<lint>&arr,lint k){
    if(k>=arr.size() || arr.size()==1){return 1;}
    map<lint,lint>mp;
    forloop(0,arr.size()){mp[arr[i]]++;}
    vector<lint>newarr;
    for(auto it=mp.begin();it!=mp.end();it++){
        lint freq=it->second;
        newarr.push_back(freq);
    }
    if(k==0){
        return newarr.size();
    }
    sort(newarr.begin(),newarr.end());
    forloop(0,newarr.size()){
        lint frequency = newarr[i];
        if(k>0){
            if(k>=newarr[i]){
                k-=newarr[i];
                newarr[i]=0;
            }
        }
    }lint cnt=0;
    forloop(0,newarr.size()){
        if(newarr[i]>0){cnt++;}
    }
    return cnt;
}

void solution(int test){
    while(test--){
        lint n;lint k;
        cin >> n >> k;
        vector<lint>arr;
        forloop(0,n){lint x;cin >> x;arr.push_back(x);}
        lint ans=solvefunction(arr,k);
        print(ans)

    }
}
int main(){
    int test;
    cin >> test;
    solution(test);
}

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

using i64 = long long;

void solve() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    std::sort(a.begin(), a.end());
    std::vector<int> cnt = {1};
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            cnt.back()++;
        } else {
            cnt.emplace_back(1);
        }
    }
    std::sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    for (int i = 0; i < m - 1; i++) {
        if (cnt[i] > k) {
            std::cout << m - i << "\n";
            return;
        }
        k -= cnt[i];
    }
    std::cout << 1 << "\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    std::cin >> t;

    while (t--) {
        solve();
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

int t, n, l, r, tem;
ll MIN_a, MIN_b;
vector<int> a, b;

int main(){
    cin >> t;
    while(t--){
        a.clear();
        b.clear();
        MIN_a = 0;
        MIN_b = 0;
        cin >> n >> l >> r;
        for(int i=0; i<n; i++){
            cin >> tem;
            if(i<r) a.push_back(tem);
            if(i>=l-1) b.push_back(tem);
        }
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        for(int j=0; j<r-l+1; j++){
            MIN_a += a[j];
            MIN_b += b[j];
        }

        cout << min(MIN_a,MIN_b) << endl;
    }
    
    return 0;
}

Solution 2 (runtime: 93 ms):
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define ld long double
#define pb push_back
#define P pair<int, int>
#define F first
#define S second
#define inf 3e18
#define mod 1000000007
#define vi vector<int>
#define ps(x, y) fixed << setprecision(y) << x
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >
#define FIO                     \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)

const int N = 100005;

// a1 a2 a3 a4 a5 a6 a7 a8 a9 a10

// 4-12

int32_t main() {
  FIO;

  int t;
  cin >> t;
  while (t--) {
    int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> n;

    int l, r;
    cin >> l >> r;
    l--;
    r--;

    vi v(n);
    vi flist, mlist, llist;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      if (i < l) {
        flist.pb(v[i]);
      } else if (i > r) {
        llist.pb(v[i]);
      } else {
        mlist.pb(v[i]);
      }
    }

    sort(flist.begin(), flist.end());
    sort(llist.begin(), llist.end());
    sort(mlist.rbegin(), mlist.rend());

    int fsum = 0, lsum = 0;
    for (int i = 0; i < r - l + 1; i++) {
      if (i < flist.size() && mlist[i] > flist[i]) {
        fsum += flist[i];
      }else {
        fsum += mlist[i];
      }
      if (i < llist.size() && mlist[i] > llist[i]) {
        lsum += llist[i];
      } else {
        lsum += mlist[i];
      }
    }

    cout << min(lsum, fsum) << "\n";
  }
  return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int tc;
    cin>>tc;
    while(tc--){
        string s;
        cin>>s;
        vector<int>v(s.size());
        for(int i=0;i<s.size();i++){
            v[i]=s[i]-'0';
        }
        for(int i=1;i<s.size();i++){
            int ci=i;
            while(ci>=1&&v[ci]>0&&v[ci]>v[ci-1]+1){
                int r=v[ci];
                v[ci]=v[ci-1];
                v[ci-1]=r-1;
                if(ci>1){
                    ci--;
                }
                else{
                    break;
                }
            }
        }
        for(auto it:v){
            cout<<it;
        }
        cout<<endl;
        
    }
}

Solution 2 (runtime: 61 ms):
// @author : yassjd199
//
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vii;
typedef vector<long long> vll;
double eps = std::numeric_limits<double>::epsilon();
#define f first
#define s second
#define pb push_back
#define endl '\n'
#define ll  long long int
#define ull unsigned long long int
const int dx[4] = {0, 0, -1, 1}, dy[4] = { -1, 1, 0, 0};
//const int dx[8] = {0, 0, -1, 1, -1, -1, 1, 1} , dy[8] = {-1, 1, 0, 0, -1, 1, -1, 1};
const long long mod = 1e9 + 7;
const int N = 1e6 + 1, M = 20;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename K, typename V> using Map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

void dbg_out() {
	cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
	cerr << ' ' << H;
	dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)





void testcase() {

	string str; cin >> str;
	int n = (int)str.size();
	string tmp;
	for (int i = 0; i < n ; i++) {

		int ans = str[i] - '0';
		int pos = i;
		for (int j = i + 1; j < min(i + 9, n); j++) {
			int diff = j - i;
			if (ans < str[j] - '0' - diff) {
				ans = str[j] - '0' - diff;
				pos = j;
			}
		}
		for (int k = pos; k > i; k--) {
			swap(str[k], str[k - 1]);
		}
		str[i] = ans + '0';
		//dbg(i, ans, pos, str);
	}

	cout << str << endl;







}

int main() {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int _ = 1;
	//int __ = 1;
	clock_t z = clock();
	cin >> _;

	while (_--) {
		//cout<<"Case #"<<__++<<": ";
		testcase();
	}

	cerr << endl << "Run Time: " << (( double ) ( clock() - z ) / CLOCKS_PER_SEC ) << endl;
	return 0;
}

/*   /\_/\
*   (= ._.)
*   / >  \>
*/
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e3+10,INF=1e9;
int f[N][N];
string a,b,c;
int n,m,k;

int dfs(int u,int i,int j)
{
	if(u==0)return 0;
	if(f[i][j]!=INF)return f[i][j];
	
	int res=INF;
	
	if(i)res=min(res,dfs(u-1,i-1,j)+(c[u]!=a[i]));
	if(j)res=min(res,dfs(u-1,i,j-1)+(c[u]!=b[j]));
	
	return f[i][j]=res;
}

void ASDOAN()
{
	cin>>a>>b>>c;
	n=a.size(),m=b.size();
	k=n+m;
	a=" "+a;
	b=" "+b;
	c=" "+c;
	
	for(int i=0;i<=n+2;i++)
	{
		for(int j=0;j<=m+2;j++)
		{
			f[i][j]=INF;
		}
	}
	
	cout<<dfs(k,n,m)<<"\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int T=1;
	cin>>T;
	while(T--)
	{
		ASDOAN();
	}
	
	return 0;
}

Solution 2 (runtime: 62 ms):
#include <cstdio>
#include <string>
#include <vector>
char buf[2000 + 3], buf1[1000 + 3], buf2[1000 + 3];
struct triple {
    int ind1;
    int ind2;
    int count;
};
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf(" %s %s %s", buf1, buf2, buf);
        std::string str1(buf1), str2(buf2), str(buf);
        int n = str1.size(), m = str2.size();
        std::vector<std::vector<int>> dp(n + 5, std::vector<int> (m + 5));
        dp[0][0] = 0;
        for (int i = 0; i < n; i++) {
            dp[i + 1][0] = dp[i][0] + (str1[i] != str[i]);
        }
        for (int i = 0; i < m; i++) {
            dp[0][i + 1] = dp[0][i] + (str2[i] != str[i]);
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                dp[i][j] = std::min(dp[i - 1][j] + (str1[i - 1] != str[i + j - 1]),
                                    dp[i][j - 1] + (str2[j - 1] != str[i + j - 1]));
            }
        }
        printf("%d\n", dp[n][m]);
    }
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

Solution 2 (runtime: 202 ms):
#include <algorithm>
#include <climits>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;

void solve(vector<ll> a, int k) {
    if(k >= a.size()) {
        cout << "1" << endl;
        return;
    }
    map<ll, ll> m;
    for(int el: a) {
        m[el]++;
    }
    vector<pair<ll, ll>> v;
    copy(m.begin(), m.end(), back_inserter(v));
    sort(v.begin(), v.end(), [](auto &left, auto &right) {
        return left.second > right.second;
    });
    while(k-- && !v.empty()) {
        if(v.back().second != 0) {
            v.back().second--;
            if(v.back().second == 0) {
                v.pop_back();
            }
        }
    }
    cout << v.size() << endl;
}

int main() {
    int t; cin >> t;
    cout << endl;
    cout << endl;
    while(t--) {
        int n, k; cin >> n >> k;
        vector<ll> a(n, 0);
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        solve(a, k);
    }
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 312 ms):
#include <cstdio>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
const int maxn = 2e5 + 50;
inline int rd() {
    int sum = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        sum = sum * 10 + ch - '0';
        ch = getchar();
    }
    return f * sum;
}
int n, t, ans;
struct F {
    int a, u;
} f[maxn];
vector<int> g[maxn];
void dfs(int u, int fa) {
    priority_queue<int> q;
    for (auto v : g[u]) {
        if (v == fa)
            continue;
        dfs(v, u);
        if (f[v].a > f[u].a)
            f[u].a = f[v].a, f[u].u = f[v].u;
        q.push(f[v].a);
        if (f[v].u == v)
            ans = max(ans, f[v].a + (int)g[u].size() - 1);
        else
            ans = max(ans, f[v].a + (int)g[u].size());
    }
    if ((int)g[u].size() - 1 > f[u].a)
        f[u].a = (int)g[u].size() - 1, f[u].u = u;
    if ((int)g[u].size() == 1)
        f[u].u = u;
    if (q.size() >= 2) {
        int x = q.top();
        q.pop();
        ans = max(ans, x + q.top() + 1);
    }
    while (!q.empty())
        q.pop();
}
void work() {
    n = rd();
    for (int i = 1; i < n; i++) {
        int u = rd(), v = rd();
        g[u].push_back(v), g[v].push_back(u);
    }
    ans = 0;
    dfs(1, 1);
    // for (int i = 1; i <= n; i++)
    //     printf("%d %d\n", f[i].u, f[i].a);
    for (int i = 1; i <= n; i++)
        f[i].u = f[i].a = 0, g[i].clear();
    printf("%d\n", ans);
}
int main() {
    // freopen("a.in","r",stdin);
    t = rd();
    while (t--)
        work();
    return 0;
}

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

signed main(){
    int tc;
    cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        map<int,map<int,int>> map1;
        map<int,int> map2;
        int maxi=0;
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            map1[u][v]=1;
            map1[v][u]=1;
            map2[u]++;map2[v]++;
        }
        map<int,int> freq;
        for(auto x : map2){
            freq[x.second]++;
        }
        int res=0;
        for(int i=1;i<=n;i++){
            // delete this one
            int u=i;
            int ans=map2[u];
            freq[ans]--;
            if(freq[ans]==0){
                freq.erase(ans);
            }
            for(auto x : map1[u]){
                freq[map2[x.first]]--;
                freq[map2[x.first]-1]++;
                if(freq[map2[x.first]]==0){
                    freq.erase(map2[x.first]);
                }
            }
            int maxi2=freq.rbegin()->first;
            res=max(res,ans+(maxi2-1));
            freq[ans]++;
            for(auto x : map1[u]){
                freq[map2[x.first]]++;
                freq[map2[x.first]-1]--;
                if(freq[map2[x.first]-1]==0){
                    freq.erase(map2[x.first]-1);
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 218 ms):
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pr_qu priority_queue
typedef pair<int, int> ii;
#define fast ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
#define koma fixed<<setprecision
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define sss "hps" // Nama File
void file(){
    freopen(sss".in","r",stdin);
    freopen(sss".out","w",stdout);
}

signed main(){
    int t; cin>>t;
    while(t--){
        int n, k; cin>>n>>k;
        int a[n+5];
        vector<int> ans;
        for(int i=1;i<=n;i++) cin>>a[i];
        sort(a+1, a+n+1);
        int cnt = 0;
        for(int i=1;i<=n;i++){
            cnt++;
            if(a[i] != a[i+1] || i == n){
                ans.pb(cnt);
                cnt = 0;
            }
        }
        sort(ans.begin(), ans.end(), greater<int>());
        int idx = ans.size()-1;
        while(k > 0){
            if(ans[idx] <= k){
                k -= ans[idx];
                ans.ppb();
                idx--;
            }
            else break;
        }
        int res = ans.size();
        cout<<max(res, 1ll)<<endl;
    }
}


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

int solve()
{
    int n, k, num;
    cin >> n >> k;

    map<int, int> mp;

    for (int i = 0; i < n; i++)
    {
        cin >> num;
        mp[num]++;
    }

    vector<int> arr;
    for (auto it : mp)
    {
        int first = it.first;
        int second = it.second;

        arr.push_back(second);
    }

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

    int ans = (int)mp.size();
    for (int i = 0; i < arr.size(); i++)
    {
        if (k - arr[i] >= 0)
        {
            k = k - arr[i];
            ans--;
        }
        else
            break;
    }
    return max(ans, 1);
}

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

    int t;
    cin >> t;

    while (t--)
        cout << solve() << endl;

    return 0;
}