General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
138670454 Practice:
mkmeden
1335C - 18 C++17 (GCC 7-32) Runtime error on test 1 15 ms 144 KB 2021-12-10 21:45:41 2021-12-10 21:45:41
→ Source
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
ull gcd(ull a , ull b)
{
  if(b==0)
  return a;
 
  return gcd(b, a%b);
}

bool work(int arr[], int n , int k )
{
  unordered_map<int ,int >hash;

  for(int i =0 ;i<n ; i++)
  {
    hash[arr[i]]++;
  }

  bool flag = false;
  for(auto x : hash)
  {
    if(x.second >= k)
    {
        flag = true ;

        hash[x.first]-= k;

        if(hash[x.first]==0)
        hash.erase(x.first);

    }
    
  }

  if(flag == false)
  return false;

  if(hash.size()>=k)
  return true;

  else 
  return false;
}

void solve()
{
  int n ; 
  cin>>n ;

  int arr[n];

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

  if(n==1)
  {
    cout<<0<<endl;
    return;
  }

  int low = 1 ,  high = n/2 ;

  int res = INT_MIN;

  while(low<=high)
  {
    int mid = (low + high)>>1;

    if(work(arr , n , mid))
    {
      res = max(res , mid);
    }


    low = mid+1 ; 

  }

  cout<<res<<endl;
} 

int  main()
{ 
    IOS;  
 // freopen("input.txt" , "r", stdin);
  //freopen("output.txt" , "w" , stdout);
    unsigned long long  t;
      cin>>t;
 
    while(t--)
    {
         solve();
    }
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details