博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #631 (Div. 2)A. Dreamoon and Ranking Collection
阅读量:4034 次
发布时间:2019-05-24

本文共 2598 字,大约阅读时间需要 8 分钟。

Dreamoon is a big fan of the Codeforces contests.

One day, he claimed that he will collect all the places from 1 to 54 after two more rated contests. It’s amazing!

Based on this, you come up with the following problem:

There is a person who participated in n Codeforces rounds. His place in the first round is a1, his place in the second round is a2, …, his place in the n-th round is an.

You are given a positive non-zero integer x.

Please, find the largest v such that this person can collect all the places from 1 to v after x more rated contests.

In other words, you need to find the largest v, such that it is possible, that after x more rated contests, for each 1≤i≤v, there will exist a contest where this person took the i-th place.

For example, if n=6, x=2 and a=[3,1,1,5,7,10] then answer is v=5, because if on the next two contest he will take places 2 and 4, then he will collect all places from 1 to 5, so it is possible to get v=5.

Input

The first line contains an integer t (1≤t≤5) denoting the number of test cases in the input.

Each test case contains two lines. The first line contains two integers n,x (1≤n,x≤100). The second line contains n positive non-zero integers a1,a2,…,an (1≤ai≤100).

Output

For each test case print one line containing the largest v, such that it is possible that after x other contests, for each 1≤i≤v, there will exist a contest where this person took the i-th place.

Example

input
5
6 2
3 1 1 5 7 10
1 100
100
11 1
1 1 1 1 1 1 1 1 1 1 1
1 1
1
4 57
80 60 40 20
output
5
101
2
2
60

Note

The first test case is described in the statement.

In the second test case, the person has one hundred future contests, so he can take place 1,2,…,99 and place 101 on them in some order, to collect places 1,2,…,101.

这个题关键是读懂题,题目太难懂了,需要反复读题才能明白

题意:
x是指未来的比赛场次,具体对应的比赛名次
目的是让,名次能从1,2,3,…,v-1,v.
x若取得好,就可以让v值取最大

可以结合样例模拟一下

#include 
using namespace std;const int N = 1e5 + 10;int a[N];int v[N];int main(){
int t; cin >> t; while (t--) {
int n, x; cin >> n >> x; memset(v, 0, sizeof(v)); for (int i = 1; i <= n; i++) {
cin>>a[i]; v[a[i]] = 1; } int p; for (int i = 1; i <= 200; i++) if (v[i] == 0) {
x--; if (x==0) {
p = i; break; } } for (int i = p + 1; i <= 200; i++) if (v[i] == 0) break; else p = i; printf("%d\n", p); } return 0;}

码字不易,留个赞吧~

转载地址:http://qafdi.baihongyu.com/

你可能感兴趣的文章
所谓的进步和提升,就是完成认知升级
查看>>
昨夜今晨最大八卦终于坐实——人类首次直接探测到了引力波
查看>>
如何优雅、机智地和新公司谈薪水?
查看>>
为什么读了很多书,却学不到什么东西?
查看>>
长文干货:如何轻松应对工作中最棘手的13种场景?
查看>>
如何用好碎片化时间,让思维更有效率?
查看>>
No.147 - LeetCode1108
查看>>
No.174 - LeetCode1305 - 合并两个搜索树
查看>>
No.175 - LeetCode1306
查看>>
No.176 - LeetCode1309
查看>>
No.182 - LeetCode1325 - C指针的魅力
查看>>
mysql:sql create database新建utf8mb4 数据库
查看>>
mysql:sql alter database修改数据库字符集
查看>>
mysql:sql drop table (删除表)
查看>>
mysql:sql truncate (清除表数据)
查看>>
scrapy:xpath string(.)非常注意问题
查看>>
yuv to rgb 转换失败呀。天呀。谁来帮帮我呀。
查看>>
yuv420 format
查看>>
YUV420只绘制Y通道
查看>>
yuv420 还原为RGB图像
查看>>