Young Explorers

Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties…
Most of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter eiei — his inexperience. Russell decided that an explorer with inexperience ee can only join the group of ee or more people.Now Russell needs to figure out how many groups he can organize. It’s not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.InputThe first line contains the number of independent test cases T(1≤T≤2⋅105). Next 2Tlines contain description of test cases.The first line of description of each test case contains the number of young explorers NN (1≤N≤2⋅105).The second line contains NN integers e1,e2,…,eN (1≤ei≤N), where eiei is the inexperience of the ii-th explorer.It’s guaranteed that sum of all NN doesn’t exceed 3⋅105.OutputPrint TT numbers, each number on a separate line.In i-th line print the maximum number of groups Russell can form in i-th test case.
Example
input
2
3
1 1 1
5
2 3 1 2 2
output
3
2
NoteIn the first example we can organize three groups. There will be only one explorer in each group. It’s correct because inexperience of each explorer equals to 1, so it’s not less than the size of his group.In the second example we can organize two groups. Explorers with inexperience 1, 2 and 3will form the first group, and the other two explorers with inexperience equal to 2 will form the second group.This solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to 2, and the second group using only one explorer with inexperience equal to 1. In this case the young explorer with inexperience equal to 3 will not be included in any group.

#include<iostream>
using namespace std;
int main()
{
 int t,m=0;
 cin>>t;
 for(int f=0;f<t;f++)
 {
  int n=0;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++)
  {
   cin>>a[i];
  }
  for(int i=0;i<n-1;i++)
  {
   for(int j=0;j<n-1-i;j++)
   {
    if(a[j]>a[j+1])
    {
     int t=a[j];
     a[j]=a[j+1];
     a[j+1]=t;
    }
   }
  }
  for(int k=0;k<n-1;k++)
  {
   if(a[k]!=a[k+1])
   {
    b[m++]=a[k];
   }
  }
  if(a[n-2]!=a[n-1])
  {
   b[m++]=a[n-1];
  } 
  if(m==0)
  {
   int c1=0;
   for(int e=0;e<n;e++)
   {
    if(a[e]==b[0])
    {
     c1++;
    }
   }
   cout<<c1<<endl; 
  }
  else if(m>0)
  {
   int c2=0;
   for(int d=0;d<m;d++)
   {
    int c1=0;
    for(int e=0;e<n;e++)
    {
     if(a[e]==b[d])
     {
      c1++;
     }
    }
    if(c1>=b[d])
    {
     c2++;
    }
   }
   cout<<c2<<endl;
  }
 } 
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

【执珪】瑕瑜·夕环玦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值