Codeforces Round #631 (Div. 2) A. Dreamoon and Ranking Collection(水题)

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
第一次见这么啰嗦的A题(相比之下
大意就是给一个序列,可能有重复数字,有x次机会为这个序列填上一个数字,问最终从里面获得的1~v连续子序列的v最大是多少。
数据范围很小,先sort一遍,然后把长度为2的空缺区间用x补上,看最多能补到哪里。
#include 
using namespace std;
int n,x,a[105];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>x;
        int i;
        for(i=1;i<=n;i++)scanf("%d",&a[i]);
        sort(a+1,a+n+1); 
        int cnt=0;
        a[n+1]=0x3f3f3f3f;//处理最后一位 因为有可能是1 1 1 1 1这样
        for(i=1;i<=n+1;i++)
        {
            int temp=a[i]-a[i-1];
            if(a[i]==a[i-1])continue;//重复跳过
            if(temp==1)
            {
                cnt=a[i];//不需要动用x
            }
            else
            {
                if(x>=temp-1)//能填上当前区间
                {
                    cnt=a[i];
                    x-=(temp-1);
                }
                else//不能
                {
                    cnt+=x;
                    break;
                }
            }
         } 
         cout<endl;
    }
    return 0;
}

 

你可能感兴趣的:(Codeforces Round #631 (Div. 2) A. Dreamoon and Ranking Collection(水题))