Div2 1355 B

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 e i e_i ei — his inexperience. Russell decided that an explorer with inexperience e e e can only join the group of e e e 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 T T T( 1 ≤ T ≤ 2 ⋅ 1 0 5 1 \leq T \leq 2 \cdot 10^5 1T2105). Next 2 T 2T 2T lines contain description of test cases.

The first line of description of each test case contains the number of young explorers N N N ( 1 ≤ N ≤ 2 ⋅ 1 0 5 1 \leq N \leq 2 \cdot 10^5 1N2105).

The second line contains N N N integers e 1 , e 2 , … , e N e_1, e_2, \ldots, e_N e1,e2,,eN ( 1 ≤ e i ≤ N 1 \leq e_i \leq N 1eiN), where e i e_i ei is the inexperience of the i i i-th explorer.

It’s guaranteed that sum of all N N N doesn’t exceed 3 ⋅ 1 0 5 3 \cdot 10^5 3105.

Output

Print T T T numbers, each number on a separate line.

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

Example

input

2
3
1 1 1
5
2 3 1 2 2

output

3
2

Note

In 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 1 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 1 1, 2 2 2 and 3 3 3 will form the first group, and the other two explorers with inexperience equal to 2 2 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 2 2, and the second group using only one explorer with inexperience equal to 1 1 1. In this case the young explorer with inexperience equal to 3 3 3 will not be included in any group.

Part1 分析题意

给出 n n n个人的经验不足程度,经验不足的 𝑒 探险家只能加入 𝑒 人或更多人的小组

求最终最多可以分配多少个组。

Part2 解题思路

错误的尝试

初作这一道题的时候,没注意到 e i ≤ n e_i \leq n ein,想到的方法很朴素

先对集合排序,接着判断是否 i + a [ i ] i + a[i] i+a[i]是否出界,同时还需要判断每一个小组的尾部元素是否出界进行判断

Error Judge

正解

根据输出结果的描述,我们会发现 e i ≤ n e_i \leq n ein,结合案例

5
2 3 1 2 2
Calc的流程

将1独自分为一组,同时并没有为2预留人数

接着我们会发现有3个2,但是我们只需要将2个2分为一组,把剩下一个用来和3去凑三个人

来到3,我们会发现加上之前的一个2,我们不足三人,结束循环

注意:用memset的话,会TLE O!

Part3 C o d e Code Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) begin(x),end(x)
#define str string

map<int,int> rmap;
inline void solve() { 
    rmap.clear(); 
    int n,t; cin >> n;
    for(int i{};i < n;i++) {
        cin >> t; rmap[t]++;
    }

    int lx = 0,cnt = 0;
    for(int i = 1;i <= n;i++) {
        cnt += (rmap[i] + lx) / i;
        lx = (rmap[i] + lx) % i;
    }

    cout << cnt << endl;    
}


int main(){
    // freopen("input.txt","r",stdin);
    int t; cin >> t;
    while(t--) solve();

    // solve();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值