B. Young Explorers

B. Young Explorers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

网址:http://codeforces.com/contest/1355/problem/B

思路 :从小到大排序一下, 再for循环累加一个num,当num大于等于a[i]时 ans+1,num=0或num-=a[i].

int main()
{
    int t;
    scanf("%d", &t);    
    int a[maxn] = { 0 };
    while (t--)
    {
        int n;
        scanf("%d", &n);

        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
        }
        int ans = 0;
        sort(a , a  + n);
        int num = 0;
        for (int i = 0; i < n; i++)
        {
            num++;
            if (num >= a[i])ans++, num = 0;
        }
        printf("%d\n", ans);
    }
    return 0;
}

循环内开数组和循环外开数组时间不同,前者较长。。

猜你喜欢

转载自www.cnblogs.com/yin101/p/12904364.html