CF A. Dreamoon and Ranking Collection 【模拟】

A. Dreamoon and Ranking Collection
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 1iv1≤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.

Input

The first line contains an integer tt (1t51≤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 (1n,x1001≤n,x≤100). The second line contains nn positive non-zero integers a1,a2,,ana1,a2,…,an (1ai1001≤ai≤100).

Output

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

Example
input
Copy
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
Copy
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,,991,2,…,99 and place 101101 on them in some order, to collect places 1,2,,1011,2,…,101

Put translation

A, Dreamoon and Ranking Series
Testing each one second time limit
The memory limit per test 256 megabytes
Input standard input
Standard output
Dreamoon is a big fan of Codeforces contest.
 
One day, he claimed that he would collect all over the place, from 1-54, and then two score game. Amazing!
 
Based on this, you will find the following questions:
 
There is a people attended the joint forces of n rounds. His place in the first round is a1, the position in the second round is a2, ...... n-th wheel in the position he is A.
 
To give you a positive non-zero integer x.
 
Please find the maximum of v, so that person can collect all places, from 1 to v, x more scoring game.
 
In other words, you need to find the biggest v, which makes it possible, after x number of higher competition score for each 1≤i≤v, there is a match, the person occupying the i-th position.
 
For example, if n = 6, x = 2 and a = [3,1,1,5,7,10] answer is v = 5, because if the next game, he will get two 2 and 4 position, then he would collect all the position 1-5, it is possible to obtain v = 5.
 
Entry
The first row contains an integer t (1≤t≤5), indicates the number of test inputs.
 
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 integer a1, a2, ..., an (1≤ai≤100).
 
Export
For each test, the maximum print a row of v, so that after x number of other contests, for each 1≤i≤v, there will be a person occupying the i-th bit of the contest.
 
example
Enter Copy
5
62 Ge
3 1 5 7 10
1100
100
11 1
1 1 1 1 1 1 1 1 1 1 1 1 1
11
1
457
80 60 40 20 th
Copy output
5
101
2
2
60
note
Statement described the first test case.
 
In a second test case, the person 100 has the next game, he may be performed in a certain order 1,2, ..., 99 and 101 on the position to collect 1, 2, ..., 101 positions.

 Qingming ancestors had to make up the title today]

This title means ... I think quite a while did not understand ...

In fact, it is such that each set of test data is given and the number n can add a number of x, and n digital to want to know where the maximum number of consecutive continuously, starting at 1 [which will make up less, Up to complement x times

Know the meaning of this title, this title became cute, you can put the number n is stored in an array, and then traverse the time, if a vacancy to fill and then X--; when X == 0 it [ after a number of run] come out, and then traverse the time to find the last one in a row and not [to find friends ^^ 0

. 1 #include <bits / STDC ++ H.>
 2  #define LL longlongs
 . 3  the using  namespace STD;
 . 4  int A [ 1002 ]; // open space otherwise distressed debug array can not die 
. 5  int main () {
 . 6       int T;
 . 7       CIN >> T;
 . 8  the while (T-- ) {
 . 9      int n-, X;
 10      CIN >> >> n- X;
 . 11      // set {0 ..... painful important lessons 
12 is      Memset (A, 0 , the sizeof (A)); // array set to zero 
13 is     for ( int I = 0 ; I <n-; I ++ ) {
 14          int m;
 15          CIN >> m;
 16          A [m] = . 1 ; // set this position is occurred 
. 17      }
 18 is      int J = . 1 ;
 . 19      the while ( . 1 ) {
 20 is          iF (a [J] == 0 ) { // if this location does not appear, but I have the time to fill the remaining x 
21 is              x--; // number of times x is one less 
22 is              a [ J] = 1 ; // this location mended 
23         }
 24          IF (x <= 0 ) BREAK ; // number of times x is not the out of the loop; 
25          J ++ ;
 26 is      }
 27      / * for (int I = 0; I <100; I ++) COUT << A [I] < < ''; // used to debug the own 
 28      COUT << "\ n-';
 29      * /     
30      int in Flag = 0 ;
 31 is      for ( int I = . 1 ; I <= 1002 ; I ++) { // iterate again see which place not from 
32          iF (a [I] == 0 ) { // when this position is 0 when the instructions to which ended 
33             = I- In Flag 1 ; // Save the last one because the former is a position 0 of 
34 is              BREAK ;
 35          }
 36      }
 37 [      COUT In Flag << << ' \ n- ' ; // output 
38 is  }
 39  return  0 ;
 40 }

 

 

 

Guess you like

Origin www.cnblogs.com/ahijing/p/12636189.html