Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- #define fr(i,k) for(i=0;i<k;i++)
- #define ALL(c) (c).begin(),(c).end()
- #define deb(x) cerr<<#x<<" = "<<x<<endl;
- #define SZ(x) (x).size();
- #define ll long long
- #define MOD 1000000007
- #define mp make_pair
- #define ff first
- #define ss second
- #define pb push_back
- #define em emplace_back
- #define ulli unsigned long long int
- #define INF 1e18
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef vector<bool> vb;
- typedef pair<int, int> ii;
- void solve();
- void err(istream_iterator<string> it) {}
- template<typename T, typename... Args>
- void err(istream_iterator<string> it, T a, Args... args) {
- cerr << *it << " = " << a << endl;
- err(++it, args...);
- }
- int main() {
- fastio;
- /*#ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif*/
- int t;
- //t=1;
- cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
- bool Possible(map<int,int> &m,int f,int j,int mid)
- {
- ll c=0;
- for(auto k:m)
- {
- if(k.first==j)
- continue;
- if(k.second>=f)
- mid--;
- if(k.second<f)
- c+=k.second;
- if(mid==0)
- return true;
- }
- if(mid*1LL*f-c>0)
- return false;
- return true;
- }
- void solve()
- {
- int n,i,j,mx=INT_MIN,l,h,mid,ans=0;
- cin>>n;
- int a[n];
- map<int,int> m;
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- m[a[i]]++;
- if(m[a[i]]>mx)
- {
- mx=m[a[i]];
- j=a[i];
- }
- }
- l=0;
- h=n;
- while(l<=h)
- {
- mid=l+(h-l)/2;
- if(Possible(m,mx-1,j,mid))
- {
- ans=mid;
- l=mid+1;
- }
- else
- h=mid-1;
- }
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement