Codeforces Round #643 (Div. 2) B. 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.

Input

The first line contains the number of independent test cases TT (1T21051≤T≤2⋅105 ). Next 2T2T lines contain description of test cases.

The first line of description of each test case contains the number of young explorers NN (1N21051≤N≤2⋅105 ).

The second line contains NN integers e1,e2,,eNe1,e2,…,eN (1eiN1≤ei≤N ), where eiei is the inexperience of the ii -th explorer.

It's guaranteed that sum of all NN doesn't exceed 31053⋅105 .

Output

Print TT numbers, each number on a separate line.

In ii -th line print the maximum number of groups Russell can form in ii -th test case.

Example
Input
Copy
2
3
1 1 1
5
2 3 1 2 2
Output
Copy
3
2
首先把數組從小到大sort一遍,然后從頭開始遍歷。
每到一個數先++cnt,如果這時cnt==當前的a[i]說明能湊成一組了,直接ans++,同時cnt=0置零。

貪心策略就是用盡可能少的數湊出來一組,因此要從小到大遍歷。
比如 1 1 3,從小到大能湊出兩組:1和1,從大到小只能湊出一組3 1 1。
#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int i;
        for(i=1;i<=n;i++)scanf("%d",&a[i]);
        sort(a+1,a+n+1);
        int ans=0;
        int cnt=0;
        a[n+1]=0x3f3f3f3f;
        for(i=1;i<=n+1;i++)
        {
            cnt++;
            if(a[i]==cnt)
            {
                ans++;
                cnt=0;
            }
        }
        cout<<ans<<endl;
    }
    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM