Dreamoon is a big fan of the Codeforces contests.
One day, he claimed that he will collect all the places from 11 to 5454 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 nn Codeforces rounds. His place in the first round is a1a1, his place in the second round is a2a2, ..., his place in the nn-th round is anan.
You are given a positive non-zero integer xx.
Please, find the largest vv such that this person can collect all the places from 11 to vv after xx more rated contests.
In other words, you need to find the largest vv, such that it is possible, that after xx more rated contests, for each 1≤i≤v1≤i≤v, there will exist a contest where this person took the ii-th place.
For example, if n=6n=6, x=2x=2 and a=[3,1,1,5,7,10]a=[3,1,1,5,7,10] then answer is v=5v=5, because if on the next two contest he will take places 22 and 44, then he will collect all places from 11 to 55, so it is possible to get v=5v=5.
The first line contains an integer tt (1≤t≤51≤t≤5) denoting the number of test cases in the input.
Each test case contains two lines. The first line contains two integers n,xn,x (1≤n,x≤1001≤n,x≤100). The second line contains nn positive non-zero integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100).
For each test case print one line containing the largest vv, such that it is possible that after xx other contests, for each 1≤i≤v1≤i≤v, there will exist a contest where this person took the ii-th place.
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
5 101 2 2 60
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,…,991,2,…,99 and place 101101 on them in some order, to collect places 1,2,…,1011,2,…,101
放上翻译
清明祭祖了只好今天补题】
这题的意思...我想了了好半天没理解...
其实是这样的,它每组测试数据给出个数n和可以加上的次数x,然后给n个数字想知道它最大连续可以连续到哪个数,【从1开始少了哪个就补上,最多补x次
知道这个题的意思后,这个题就变得可爱了,就可以把这n个数储存在一个数组里,然后遍历一次,若出现空缺就补上然后X--;当X==0【就次数用完了后】跳出来,再遍历一次找到最后一个连续着且不是0的【就找到啦^^
1 #include <bits/stdc++.h>
2 #define ll longlong
3 using namespace std;
4 int a[1002];//开数组不能心疼空间不然debug会死
5 int main(){
6 int t;
7 cin>>t;
8 while(t--){
9 int n,x;
10 cin>>n>>x;
11 //设置0很重要.....【惨痛教训
12 memset(a,0,sizeof(a));//数组置0
13 for(int i=0;i<n;i++){
14 int m;
15 cin>>m;
16 a[m]=1;//设置这一个位置是否出现过
17 }
18 int j=1;
19 while(1){
20 if(a[j]==0){//当这个位置没有出现,但我还有剩余x去补的时候
21 x--;//x的次数减少一次
22 a[j]=1;//这个位置补好了
23 }
24 if(x<=0)break;//x次数没有了,跳出循环;
25 j++;
26 }
27 /*for(int i=0;i<100;i++)cout<<a[i]<<' ';//自己用来debug的
28 cout<<'
';
29 */
30 int flag=0;
31 for(int i=1;i<=1002;i++){//遍历一遍看从哪个地方不可以的
32 if(a[i]==0){//当这个位置为0的时候说明到这截至了
33 flag=i-1;//减1是因为最后一个位置是为0的前一位
34 break;
35 }
36 }
37 cout<<flag<<'
';//输出
38 }
39 return 0;
40 }