Dreamoon and Ranking Collection

Dreamoon and Ranking Collection

题面翻译

题目描述

Dreamoon 热衷于参加 Codeforces 竞赛。

一天,他声称自己再参加两场 rated 场后,就会获得过从第 1 1 1 名到第 54 54 54 名的所有名次。这真是不可思议!

基于此,你提出了如下一个问题:

张三参加了 n n n 场 Codeforces 比赛。他第一场的排名为 a 1 a_1 a1,第二场的排名为 a 2 a_2 a2,……,第 n n n 场的排名为 a n a_n an

给出一个正整数 x x x。请找到最大的 v v v,满足张三在再参加 x x x 场 rated 比赛后,有可能取得 1 1 1 v v v 中所有名次。

换句话说,你需要找到最大的 v v v,满足在继续参加 x x x 场 rated 比赛后,有可能对于任意的 1 ≤ i ≤ v 1 \le i \le v 1iv,存在一场张三排在第 i i i 名的比赛。

举个例子,如果 n = 6 , x = 2 , a = [ 3 , 1 , 1 , 5 , 7 , 10 ] n = 6, x = 2, a = [3, 1, 1, 5, 7, 10] n=6,x=2,a=[3,1,1,5,7,10],那么答案 v = 5 v = 5 v=5。因为如果接下来的两次比赛内,张三分别取得了第 2 2 2 名和第 4 4 4 名,他可以获得过第 1 1 1 名到第 5 5 5 名内的所有名次,所以 v = 5 v = 5 v=5 是可能达成的最大答案。

输入格式

第一行输入一个整数 t   ( 1 ≤ t ≤ 5 ) t ~ (1 \le t \le 5) t (1t5),表示测试数据组数。

对于每组测试数据,输入两行。

第一行输入两个整数 n , x   ( 1 ≤ n , x ≤ 100 ) n, x ~ (1 \le n, x \le 100) n,x (1n,x100)

第二行输入 n n n 个正整数 a 1 , a 2 , … , a n   ( 1 ≤ a i ≤ 100 ) a_1, a_2, \ldots, a_n ~ (1 \le a_i \le 100) a1,a2,,an (1ai100)

输出格式

对于每组测试数据,输出一行一个整数 v v v,表示在再参加 x x x 次比赛后,有可能实现对于所有 1 ≤ i ≤ v 1 \le i \le v 1iv,存在一场比赛张三排在第 i i i 名。

说明/提示

第一组测试数据的说明见【题目描述】。

对于第二组测试数据,张三将会再参加 100 100 100 场比赛,他可以以任意顺序取得第 1 , 2 , … , 99 1, 2, \ldots, 99 1,2,,99 101 101 101 名,就获得过第 1 , 2 , … , 101 1, 2, \ldots, 101 1,2,,101 名中的所有名词。

题目描述

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 $ a_1 $ , his place in the second round is $ a_2 $ , …, his place in the $ n $ -th round is $ a_n $ .

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 \leq i \leq 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 $ .

输入格式

The first line contains an integer $ t $ ( $ 1 \leq t \leq 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 \leq n, x \leq 100 $ ). The second line contains $ n $ positive non-zero integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \leq a_i \leq 100 $ ).

输出格式

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

样例 #1

样例输入 #1

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

样例输出 #1

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,\ldots,99 $ and place $ 101 $ on them in some order, to collect places $ 1,2,\ldots,101 $ .

#include<stdio.h>
#include<stdlib.h>
int compare(const void* p, const void* q)
{
	return *(int*)p - *(int*)q;
}
int find(int* arr, int n,int start,int x)
{
	int i = 0, ans=1;
	if (arr[0] != 1)
	{
		x -= 1;
	}
		while(i<n)
		{
			if (arr[i] - ans > 1)//如果遇到跳跃1个以上的数字
			{
				if (x)
				{
					x -= 1;
					ans++;
				}
				else
				{
					break;
				}
			}
			else if (arr[i] - ans == 1)
			{
				i++;
				ans++;
			}
			else
				i++;
		}
		if (x)
			ans += x;
	return ans;
}
int main(void)
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, x, arr[101] = { 0 };
		scanf("%d %d", &n, &x);
	
			for (int i = 0; i < n; i++)
			{
				scanf("%d", &arr[i]);
			}
			qsort(arr, n, sizeof(int), compare);
			int ans=find(arr, n, 1,x);
			printf("%d\n", ans);
	}
	return 0;
}

条理的重要性

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值