Dreamoon and Ranking Collection CodeForces - 1330A (贪心)

题意:

大意就是给一个序列,可能有重复数字,有x次机会为这个序列填上一个数字,问最终从里面获得的1~v连续子序列的v最大是多少。

题目:

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

分析:

其实读懂这道题的题意,基本都能写出来,A题一般都简单,这里说下我对这道题的分析:
1.我首先想到map,记录出现的值。
2.用一个while循环,直到找到第m次的“空位”
3.结果用了减二,因为while循环,先判断再运行再判断这样就会多加2
4.起始即为1,题目要求从1开始。

AC代码:

#include<stdio.h>
#include<string.h>
#include<map>
#include<algorithm>
using namespace std;
const int M=1e3+10;
int t,n,m,ans,k;
int a[M];
int main()
{scanf("%d",&t);while(t--){map<int,int>mp;scanf("%d%d",&n,&m);for(int i=0;i<n;i++){scanf("%d",&a[i]);mp[a[i]]++;}k=0;ans=1;while(k<=m){if(!mp[ans])k++;ans++;}printf("%d\n",ans-2);}
}
In addtion

最近想提高下自己博客的阅读量,就会开始尽量把以后所有写过的CodeForces,发到博客上,因为题会新一点,也希望能帮到你们,我会开一个新分类。就酱!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/309785.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[C++11]lambda表达式语法

代码如下: #include <iostream> using namespace std;void func(int x, int y) {int a;int b;[]() {int c a;//使用了外部变量&#xff0c;[]里面加个 int d x;}; }int main() {return 0; }lambda表达式的注意事项: 以上图片来自下面链接: https://subingwen.cn/cpp…

[翻译]欢迎使用C#9.0

本文由公众号[开发者精选资讯](微信号&#xff1a;yuantoutiao)翻译首发&#xff0c;转载请注明来源C# 9.0 is taking shape, and I’d like to share our thinking on some of the major features we’re adding to this next version of the language.C&#xff03;9.0初具规…

android环境搭建出错,androidstudio配置环境遇到的各种错误(持续更新中)

AndroidStudio3.0,gradle4.1&#xff0c;新建工程&#xff0c;遇到如下错误&#xff1a;Error:Unable to resolve dependency for :appdebugAndroidTest/compileClasspath: Could not resolve com.android.support.test:runner:1.0.1.Error:Unable to resolve dependency for :…

操作系统第四章习题

操作系统第四章习题 1.对一个将页表放在内存中的分页系统&#xff1a; (1) 如果访问内存需要0.2μs&#xff0c;有效访问时间为多少? (2) 如果加一快表&#xff0c;且假定在快表中找到页表的几率高达90%&#xff0c;则有效访问时间又是多少&#xff08;假定查快表需花的时间…

[C++11]右值和右值引用

代码如下: #include <iostream> using namespace std;int main() {//左值int num 9;//左值引用int &a num;//右值const int N 5;//右值引用int && b 8;//常量左值引用const int &c num;//常量右值引用const int &&d 6;//const int &&…

用html写出生日蛋糕,纯HTML5+CSS3制作生日蛋糕代码

.birthday .container{width:600px;height:600px;margin:0px auto;background: #fafafa;border-radius:5px;position: relative;}/**** 顶层的**/.birthday .top-one{position: absolute;width:280px;height: 280px;bottom: 200px;left:160px;}.birthday .top-one .bottom{posi…

我们为什么推荐在Json中使用string表示Number属性值

在这篇简短的文章中&#xff0c;我将解释在使用JSON传输数据时&#xff0c;为什么浮点数或大十进制值应表示为字符串 。long类型引发的诡异情况长话短说&#xff0c;同事在利用swagger对接后端API时&#xff0c;诡异的发现swaggerUI中显示的json属性值并不是api返回的值。[Http…

并查集+基础知识点详解

并查集概念 并查集单看名字大家也能猜到这个算法的作用&#xff0c;是用来对集合进行合并和查找操作 并查集是一种树型的数据结构&#xff0c;用于处理一些不相交集合(Disjoint Sets)的合并及查询问题。——来自百度百科 就是将原本不一样的集合&#xff0c;但是由于某种关系有…

[C++11]move资源的转移

从实现上讲&#xff0c;std::move 基本等同于一个类型转换&#xff1a;static_cast<T&&>(lvalue);&#xff0c;函数原型如下: template<class _Ty> _NODISCARD constexpr remove_reference_t<_Ty>&& move(_Ty&& _Arg) _NOEXCEPT { …

网址导航html5源码图标版,最新仿hao123网址导航(晓风网址导航系统) v4.2

使用说明 采用aspaccess架构&#xff0c;简单易用 access数据库已做防下载处理&#xff0c;安全放心 程序不能放到子目录&#xff0c;否则无法生成全站 上传程序进入后台设置一下网站信息&#xff0c;生成所有HTML页面 首页网站标志LOGO目录位置&#xff1a;/images/logo_140.g…

基于 abp vNext 和 .NET Core 开发博客项目 - 统一规范API,包装返回模型

上一篇文章使用自定义仓储完成了简单的增删改查案例&#xff0c;有心的同学可以看出&#xff0c;我们的返回参数一塌糊涂&#xff0c;显得很不友好。在实际开发过程中&#xff0c;每个公司可能不尽相同&#xff0c;但都大同小异&#xff0c;我们的返回数据都是包裹在一个公共的…

奔小康赚大钱 HDU - 2255( 二分图匹配KM算法详解)

题目 传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革&#xff1a;重新分配房子。 这可是一件大事,关系到人民的住房问题啊。村里共有n间房间,刚好有n家老百姓,考虑到每家都要有房住&#xff08;如果有老百姓没房子住的话&#xff0c;容易引起不安定因素&…

记一次排查线上程序内存的忽高忽低,又是大集合惹祸了

一&#xff1a;背景1. 讲故事昨天继续还技术债&#xff0c;优化一轮后的程序拉到线上后内存继续忽高忽低&#xff0c;低的时候20G&#xff0c;高的时候30G&#xff0c;过了一会又下降了几个G&#xff0c;毫无疑问&#xff0c;程序中有什么集合或者什么操作占用了大量内存&#…

[C++11]forward完美转发

// 函数原型 template <class T> T&& forward (typename remove_reference<T>::type& t) noexcept; template <class T> T&& forward (typename remove_reference<T>::type&& t) noexcept;// 精简之后的样子 std::forward…

广州计算机专业王健,王健-计算机与信息工程学院

2.在国内外公开发行刊物上发表的学术论文(1)Jian Wang. A Novel K-NN Classification Algorithm for Privacy Preserving in Cloud Computing. Research Journal of Applied Sciences, Engineering and Technology, Vol. 4, Issue: 22, 2012 (EI源刊).(2)Jian Wang. Experimen…

Pipe HDU - 2150(判断线段相交+向量叉乘线代详解)

题目&#xff1a; 经过激烈的争夺&#xff0c;Lele终于把那块地从Yueyue的手里抢了回来。接下来&#xff0c;Lele要开始建造他的灌溉系统。 通过咨询Lele的好友——化学系的TT&#xff0c;Lele决定在田里挖出N条沟渠&#xff0c;每条沟渠输送一种肥料。 每条沟渠可以看作是一…

win7如何将计算机移至桌面,如何将win7电脑桌面的文件转移到其他盘中?

想必很多朋友都和小编一样&#xff0c;是一个嫌麻烦的人&#xff0c;是一个不怎么爱收拾的人吧?这种人有一个通病&#xff0c;那就是喜欢将一些重要的文件放置在win7 64位纯净版下载的桌面上&#xff0c;这样的话&#xff0c;不仅容易找到&#xff0c;而且方便使用&#xff0c…

Source Generator:C# 9 将迎来编译时元编程

源码生成器&#xff08;Source Generator&#xff09;是 C#编译器的一个新特性&#xff0c;开发者可以使用编译器生成的元数据检查用户代码&#xff0c;并生成附加的源文件&#xff0c;与程序的其他部分一起编译。受 F#类型提供程序的启发&#xff0c;C#源码生成器的目标也是为…

凸包算法知识总结

首先&#xff0c;什么是凸包&#xff1f; 假设平面上有p0~p12共13个点&#xff0c;过某些点作一个多边形&#xff0c;使这个多边形能把所有点都“包”起来。当这个多边形是凸多边形的时候&#xff0c;我们就叫它“凸包”。 处理何种问题&#xff1a;凸包可以看成在木板上钉许多…