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×1ai×1 (that is, the width is 11 and the height is aiai).

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×3 square, which is the maximum possible. Note that this is not the only way he can obtain a 3×33×3 square.

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

Input

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

For each test case, the first line contains a single integer nn (1≤n≤10001≤n≤1000), the number of planks Ujan has in store. The next line contains nn integers a1,…,ana1,…,an (1≤ai≤n1≤ai≤n), the lengths of the planks.

Output

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

Example
input

Copy
4
5
4 3 1 4 5
4
4 4 4 4
3
1 1 1
5
5 5 1 1 5
output

Copy
3
4
1
3
Note

The first sample corresponds to the example in the statement.

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

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

//先从小打到排序,然后枚举最大边长
#include<bits/stdc++.h>
using namespace std;
const int maxn =;
int n,a[maxn];
void solve() {
scanf("%d",&n);
for(int i=; i<n; i++) {
scanf("%d",&a[i]);
}
sort(a,a+n);//从小到大
int ans = ;
for(int i=; i<n; i++) {//从小开始
for(int j=a[i]; j>=; j--) {//让j为a[i]的高度,然后递减
if((n-i)>=j) {// 如果大于a[i]的数目大于等于j,那么此时最大就是j
ans=max(ans,j);
break;
}
}
}
cout<<ans<<endl;
}
int main() {
int t;
scanf("%d",&t);
while(t--)solve();
}

Codeforces Round #599 (Div. 2) A. Maximum Square的更多相关文章

  1. Codeforces Round #599 (Div. 2) A. Maximum Square 水题

    A. Maximum Square Ujan decided to make a new wooden roof for the house. He has

  2. Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)

    Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...

  3. Codeforces Round #599 (Div. 2)

    久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...

  4. Codeforces Round #599 (Div. 2)的简单题题解

    难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...

  5. Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序

    B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  6. Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数

    B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...

  7. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  8. [Codeforces Round #247 (Div. 2)] A. Black Square

    A. Black Square time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #172 (Div. 2) D. Maximum Xor Secondary 单调栈应用

    http://codeforces.com/contest/281/problem/D 要求找出一个区间,使得区间内第一大的数和第二大的数异或值最大. 首先维护一个单调递减的栈,对于每个新元素a[i] ...

随机推荐

  1. Quartz.NET 2.x教程

    第1课:使用Quartz第2课:工作和触发器第3课:关于工作和JobDetails的更多信息第4课:有关触发器的更多信息第5课:SimpleTriggers第6课:CronTriggers第7课:Tr ...

  2. SpringMVC处理中文乱码

    SpringMVC自带过滤器 添加至web.xml文件 <filter> <filter-name>encoding</filter-name> <filte ...

  3. jQuery---学习roadmap---4 parts

    jQuery---学习roadmap---4 parts jQuery初识 jQuery让js的开发变得更加简单 jQuery解决了浏览器的兼容性问题 学习目标 使用jQuery设计常见的效果 掌握j ...

  4. CriteriaBuilder jpa 日期date查询

    概要:前端日期选择器选择完之后传一个String到后台,后台的字段的数据类型是date 前端: <label class="layui-form-label" >单据日 ...

  5. 本地项目如何上传到github

      首先登录官网注册用户(此处不多介绍),然后需要登录github创建仓库 https://github.com/ 然后取一个自己喜欢的名字(这里我的名字是webclock),点击Create rep ...

  6. 简单易用,用Powershell劫持Windows系统快捷键

    POC:  $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("des ...

  7. 网易云信融合CDN方案及实践

    日前,网易云信视频云架构师席智勇在第七届GFIC全球家庭互联网大会进行了题为<网易云信融合CDN方案及实践>的分享,以下是演讲内容回顾. 图为 网易云信视频云架构师席智勇 CDN所面临的问 ...

  8. SD卡报错“error -110 whilst initialising SD card”

    目前开发遇到了某些SD卡和TI的SOC芯片的驱动不协调的地方,具体表现为: uboot 阶段初始化mmc dev 1 没有任何串口信息输出,无法读写mmc Kernel阶段报错”SD卡初始化失败 er ...

  9. 函数的应用_python

    一.各类函数应用 1.高阶函数:函数里面调用函数 例子: def add(a): return (a*a) def print_info(fun,c,d): #传入函数与参数 return fun(c ...

  10. EF CodeFirst 之 Fluent API

    如何访问Fluent API: 在自定义上下文类中重写OnModelCreating方法,在方法内调用. 注:用法基本一样,配置类中的this就相当于modelBuilder.Entity<Pe ...