#K60252. Maximize the Minimum Team Energy
Maximize the Minimum Team Energy
Maximize the Minimum Team Energy
You are given n participants, each with a certain energy level. Your task is to form a team such that the minimum energy level among the team members is maximized. More formally, after sorting the energy levels in non-decreasing order, you want to choose a subset of participants and maximize the value
$$\max_{0\le i<n} \min\bigl(\text{energy}[i],\, n-i\bigr) $$For each test case:
- The first line contains an integer
n
representing the number of participants. - The second line contains
n
space-separated integers denoting the energy levels of the participants.
You are to process T
test cases. For each test case, output the maximum possible value as described above. This value represents the highest achievable minimum energy level, given that if you select a group of size k
, the minimum energy level in that group must be at least k
in order for the team to be considered strong.
inputFormat
The input is read from stdin and has the following format:
T n energy1 energy2 ... energyn ... (repeated T times)
Where T
represents the number of test cases. For each test case, n
is the number of participants followed by a line of n
integers indicating their energy levels.
outputFormat
For each test case, output a single integer on a new line representing the maximum possible minimum energy level of the team formed. The output is written to stdout.
## sample2
4
1 3 6 2
5
4 2 7 1 3
2
3
</p>