CF1358B.Maria Breaks the Self-isolation
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 n friends who are also grannies (Maria is not included in this number). The i-th granny is ready to attend the ceremony, provided that at the time of her appearance in the courtyard there will be at least ai other grannies there. Note that grannies can come into the courtyard at the same time. Formally, the granny i 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 ai.
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 1). All the remaining n 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 ai 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 i-th granny in the moment of appearing in the courtyard, finds that now there are strictly less than ai 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=6 and a=[1,5,4,5,1,9], then:
- at the first step Maria can call grannies with numbers 1 and 5, each of them will see two grannies at the moment of going out into the yard (note that a1=1≤2 and a5=1≤2);
- at the second step, Maria can call grannies with numbers 2, 3 and 4, each of them will see five grannies at the moment of going out into the yard (note that a2=5≤5, a3=4≤5 and a4=5≤5);
- the 6-th granny cannot be called into the yard — therefore, the answer is 6 (Maria herself and another 5 grannies).
玛丽亚是她家中最活跃的老奶奶。她厌倦了整天待在家里,于是决定举办一场对抗新冠病毒的仪式。
她有 n 位朋友,也都是老奶奶(注意:玛丽亚本人不计入这 n 人之中)。第 i 位老奶奶愿意出席仪式,当且仅当她在庭院中现身的那一刻,庭院中至少已有 ai 位其他老奶奶。注意:多位老奶奶可以同时进入庭院。形式化地说,老奶奶 i 同意前来,当且仅当在她出现时刻,早于或与她同时抵达庭院的其他老奶奶人数(即不包括她自己,但包括玛丽亚)≥ai。
老奶奶们按如下方式聚集到庭院中:
- 初始时,庭院中仅有玛丽亚一人(即初始老奶奶人数为 1),其余 n 位老奶奶仍待在各自家中。
- 每一步,玛丽亚从尚未进入庭院的老奶奶中选出一个子集,并向其中每一位承诺:当她们出现在庭院中时,庭院中将至少已有 ai 位其他老奶奶(包括玛丽亚)。玛丽亚可同时召集多位老奶奶;此时,被选中的老奶奶将在同一时刻走入庭院。
- 玛丽亚不能欺骗老奶奶——即禁止出现如下情形:老奶奶 i 在庭院中现身的瞬间,发现此时庭院中严格少于 ai 位其他老奶奶(不包括她自己,但包括玛丽亚)。请注意:若多位老奶奶同时进入庭院,则她们彼此在现身时刻均能看见对方。
你的任务是:求出玛丽亚最多能在庭院中聚集多少位老奶奶(包括她自己)来参加仪式。毕竟,在隔离期间,一个地方聚集的人越多,仪式的效果就越强!
举个例子:若 n=6,且 a=[1,5,4,5,1,9],则:
- 第一步,玛丽亚可召集编号为 1 和 5 的老奶奶;她们现身时都将看到庭院中有 2 位老奶奶(注意:a1=1≤2,且 a5=1≤2);
- 第二步,玛丽亚可召集编号为 2、3 和 4 的老奶奶;她们现身时都将看到庭院中有 5 位老奶奶(注意:a2=5≤5,a3=4≤5,且 a4=5≤5);
- 编号为 6 的老奶奶无法被召集入庭院——因此答案为 6(玛丽亚本人 + 其余 5 位老奶奶)。
输入格式
The first line contains a single integer t (1≤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 n (1≤n≤105) — the number of grannies (Maria is not included in this number).
The second line contains n integers a1,a2,…,an (1≤ai≤2⋅105).
It is guaranteed that the sum of the values n over all test cases of the input does not exceed 105.
第一行包含一个整数 t(1≤t≤104)—— 表示输入中测试用例的数量。随后是各测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤105)—— 表示奶奶们的数量(注意:Maria 不计入该数量)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤2⋅105)。
保证输入中所有测试用例的 n 值之和不超过 105。
输出格式
For each test case, print a single integer k (1≤k≤n+1) — the maximum possible number of grannies in the courtyard.
对于每个测试用例,输出一个整数 k(1≤k≤n+1)——庭院中奶奶数量的最大可能值。
输入输出样例
输入#1
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
输出#1
6 1 6 4
说明/提示
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 1, 2 and 3. If on the second step Maria calls 4 or 5 (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 4-th granny or the 5-th granny separately (one of them). If she calls both: 4 and 5, then when they appear, they will see 4+1=5 grannies. Despite the fact that it is enough for the 4-th granny, the 5-th granny is not satisfied. So, Maria cannot call both the 4-th granny and the 5-th granny at the same time. That is, Maria and three grannies from the first step will be in the yard in total.
在示例的第一个测试用例中,第一步玛丽亚可以呼叫所有老奶奶。随后,当她们走出来时,每人将看到五位老奶奶。因此,院子里将有玛丽亚和另外五位老奶奶。
在示例的第二个测试用例中,无人能进入院子,因此玛丽亚将独自留在院中。
示例的第三个测试用例已在上述细节中描述。
在示例的第四个测试用例中,第一步玛丽亚可以呼叫编号为 1、2 和 3 的老奶奶。若在第二步中玛丽亚仅呼叫 4 或 5 中的一位(即单独呼叫其中一位),则当该老奶奶出现在院子里时,她只会看到四位老奶奶(但这是被禁止的)。这意味着玛丽亚不能单独(即仅其中一位)呼叫第 4 位或第 5 位老奶奶。如果她同时呼叫第 4 位和第 5 位老奶奶,则当她们出现时,每人将看到 4+1=5 位老奶奶。尽管这对第 4 位老奶奶已足够,但第 5 位老奶奶并不满意。因此,玛丽亚不能在同一时间同时呼叫第 4 位和第 5 位老奶奶。最终,院子里总共只有玛丽亚和第一步中呼叫的三位老奶奶。
输入解题思路,AI测评打分。不知道怎么写?