Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
642 B
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define s second
#define f first
void solve(){
	int n,k,i,ans=0,b,a,p;
	multiset<int,greater<int> >s;
	cin>>n>>k;
	map<int,int>m;
	for(i=0;i<n;i++){
		cin>>a;
		m[a]++;
	}
	for(auto i:m){
		s.insert(i.s);
	}
	vector<int>v;
	while(s.size()>=k){
		b=k;
		v.clear();
		while(b--){
			v.push_back(*s.begin());
			s.erase(s.begin());
		}
		for(i=0;i<v.size();i++){
			if(v[i]>1){s.insert(v[i]-1);}
		}
		ans++;
	}
	cout<<ans<<"\n";
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}