CF1243A.Maximum Square

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ujan decided to make a new wooden roof for the house. He has nn rectangular planks numbered from 11 to nn. The ii-th plank has size ai×1a_i \times 1 (that is, the width is 11 and the height is aia_i).

Now, Ujan wants to make a square roof. He will first choose some of the planks and place them side by side in some order. Then he will glue together all of these planks by their vertical sides. Finally, he will cut out a square from the resulting shape in such a way that the sides of the square are horizontal and vertical.

For example, if Ujan had planks with lengths 44, 33, 11, 44 and 55, he could choose planks with lengths 44, 33 and 55. Then he can cut out a 3×33 \times 3 square, which is the maximum possible. Note that this is not the only way he can obtain a 3×33 \times 3 square.

What is the maximum side length of the square Ujan can get?

乌詹决定为房子制作一个新的木制屋顶。他有 nn 块矩形木板,编号从 11 到 nn。第 ii 块木板的尺寸为 ai×1a_i \times 1(即宽度为 11,高度为 aia_i)。

现在,乌詹想制作一个正方形屋顶。他将首先选出若干块木板,并以某种顺序将它们并排摆放;然后,他将所有选中的木板沿其竖直边粘合在一起;最后,他将从所得图形中裁剪出一个正方形,要求该正方形的边分别与水平和竖直方向平行。

例如,若乌詹拥有的木板长度分别为 44、33、11、44 和 55,他可选择长度为 44、33 和 55 的三块木板。此时,他能裁剪出一个 3×33 \times 3 的正方形,这是可能达到的最大边长。注意,这并非唯一能得到 3×33 \times 3 正方形的方式。

乌詹所能得到的正方形的最大边长是多少?

输入格式

The first line of input contains a single integer kk (1≤k≤101 \leq k \leq 10), the number of test cases in the input.

For each test case, the first line contains a single integer nn (1≤n≤1 0001 \leq n \leq 1\,000), the number of planks Ujan has in store. The next line contains nn integers a1,…,ana_1, \ldots, a_n (1≤ai≤n1 \leq a_i \leq n), the lengths of the planks.

输入的第一行包含一个整数 kk(1≤k≤101 \leq k \leq 10),表示输入中测试用例的数量。

对于每个测试用例,第一行包含一个整数 nn(1≤n≤1 0001 \leq n \leq 1\,000),表示Ujan库存中木板的数量。下一行包含 nn 个整数 a1,…,ana_1, \ldots, a_n(1≤ai≤n1 \leq a_i \leq n),表示各木板的长度。

输出格式

For each of the test cases, output a single integer, the maximum possible side length of the square.

对于每个测试用例,输出一个整数,即正方形可能的最大边长。

输入输出样例

  • 输入#1

    4
    5
    4 3 1 4 5
    4
    4 4 4 4
    3
    1 1 1
    5
    5 5 1 1 5

    输出#1

    3
    4
    1
    3

说明/提示

The first sample corresponds to the example in the statement.

In the second sample, gluing all 44 planks will result in a 4×44 \times 4 square.

In the third sample, the maximum possible square is 1×11 \times 1 and can be taken simply as any of the planks.

第一个样例对应题目描述中的示例。

在第二个样例中,将全部 44 块木板拼接起来会得到一个 4×44 \times 4 的正方形。

在第三个样例中,可能的最大正方形为 1×11 \times 1,可直接取任意一块木板即可。

输入解题思路,AI测评打分。不知道怎么写?

首页