Maria Breaks the Self-isolation

Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.

She has nn friends who are also grannies (Maria is not included in this number). The ii-th granny is ready to attend the ceremony, provided that at the time of her appearance in the courtyard there will be at least aiai other grannies there. Note that grannies can come into the courtyard at the same time. Formally, the granny ii agrees to come if the number of other grannies who came earlier or at the same time with her is greater than or equal to aiai.

Grannies gather in the courtyard like that.

  • Initially, only Maria is in the courtyard (that is, the initial number of grannies in the courtyard is 11). All the remaining nn grannies are still sitting at home.
  • On each step Maria selects a subset of grannies, none of whom have yet to enter the courtyard. She promises each of them that at the time of her appearance there will be at least aiai other grannies (including Maria) in the courtyard. Maria can call several grannies at once. In this case, the selected grannies will go out into the courtyard at the same moment of time.
  • She cannot deceive grannies, that is, the situation when the ii-th granny in the moment of appearing in the courtyard, finds that now there are strictly less than aiai other grannies (except herself, but including Maria), is prohibited. Please note that if several grannies appeared in the yard at the same time, then each of them sees others at the time of appearance.

Your task is to find what maximum number of grannies (including herself) Maria can collect in the courtyard for the ceremony. After all, the more people in one place during quarantine, the more effective the ceremony!

Consider an example: if n=6n=6 and a=[1,5,4,5,1,9]a=[1,5,4,5,1,9], then:

  • at the first step Maria can call grannies with numbers 11 and 55, each of them will see two grannies at the moment of going out into the yard (note that a1=1≤2a1=1≤2 and a5=1≤2a5=1≤2);
  • at the second step, Maria can call grannies with numbers 22, 33 and 44, each of them will see five grannies at the moment of going out into the yard (note that a2=5≤5a2=5≤5, a3=4≤5a3=4≤5 and a4=5≤5a4=5≤5);
  • the 66-th granny cannot be called into the yard  — therefore, the answer is 66 (Maria herself and another 55 grannies).

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases in the input. Then test cases follow.

The first line of a test case contains a single integer nn (1≤n≤1051≤n≤105) — the number of grannies (Maria is not included in this number).

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤2⋅1051≤ai≤2⋅105).

It is guaranteed that the sum of the values nn over all test cases of the input does not exceed 105105.

Output

For each test case, print a single integer kk (1≤k≤n+11≤k≤n+1) — the maximum possible number of grannies in the courtyard.

Example

input

Copy

4
5
1 1 2 2 1
6
2 3 4 5 6 7
6
1 5 4 5 1 9
5
1 2 3 5 6

output

Copy

6
1
6
4

Note

In the first test case in the example, on the first step Maria can call all the grannies. Then each of them will see five grannies when they come out. Therefore, Maria and five other grannies will be in the yard.

In the second test case in the example, no one can be in the yard, so Maria will remain there alone.

The third test case in the example is described in the details above.

In the fourth test case in the example, on the first step Maria can call grannies with numbers 11, 22 and 33. If on the second step Maria calls 44or 55 (one of them), then when a granny appears in the yard, she will see only four grannies (but it is forbidden). It means that Maria can't call the 44-th granny or the 55-th granny separately (one of them). If she calls both: 44 and 55, then when they appear, they will see 4+1=54+1=5grannies. Despite the fact that it is enough for the 44-th granny, the 55-th granny is not satisfied. So, Maria cannot call both the 44-th granny and the 55-th granny at the same time. That is, Maria and three grannies from the first step will be in the yard in total.

先把要求看到的人数从小到大排列,然后倒序叫人,因为排在最后的是要求人数最多的,排在最后的看见的人数都符合要求那么之前的人都符合要求,从后往前依次遍历一便即可 


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n,t,k,m;
ll sum,num,b;
ll a[1000010];
ll pd[1010];
ll j,o;
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(ll i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+n);
        sum=1;
        ll i;
        for( i=n;i>=0;i--)
        {
            if(a[i]<=i)
            {
                cout<<i+1<<endl;
                break;
            }
        }
        if(i==-1)
            cout<<1<<endl;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值