You are given a sequence of integers of length nn and integer number kk. You should print any integer number xx in the range of [1;109][1;109] (i.e. 1≤x≤1091≤x≤109) such that exactly kk elements of given sequence are less than or equal to xx.

Note that the sequence can contain equal elements.

If there is no such xx, print "-1" (without quotes).

Input

The first line of the input contains integer numbers nn and kk (1≤n≤2⋅1051≤n≤2⋅105, 0≤k≤n0≤k≤n). The second line of the input contains nn integer numbers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the sequence itself.

Output

Print any integer number xx from range [1;109][1;109] such that exactly kk elements of given sequence is less or equal to xx.

If there is no such xx, print "-1" (without quotes).

Examples

Input
7 43 7 5 1 10 3 20

Output
6

Input
7 23 7 5 1 10 3 20

Output
-1

Note

In the first example 55 is also a valid answer because the elements with indices [1,3,4,6][1,3,4,6] is less than or equal to 55 and obviously less than or equal to 66.

In the second example you cannot choose any number that only 22 elements of the given sequence will be less than or equal to this number because 33 elements of the given sequence will be also less than or equal to this number.

题意:

给你一个含有N个数组的数组,给你一个整数k,0<=k<=n

让你输出一个数x,使之在这N个数中,有严格的k个数小于等于x。x的范围是1~1e9

思路:

排序后,如果a[k]!=a[k+1]

输出a[k]就行了。

注意 下这几个坑点:

x的范围:1~1e9,

如果k是0,那么需要特判a[1] 是否是1

如果k为N,输出a[n]即可。

细节注意好就不会出错,。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ll n;
ll a[maxn];
int main()
{//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;cin>>n;ll k;cin>>k;repd(i,1,n){cin>>a[i];}sort(a+1,a+1+n);if(k==0){if(a[1]==1){cout<<-1<<endl;}else{cout<<1<<endl;}}else{if(a[k]!=a[k+1]){if(a[k]<=1000000000)cout<<a[k]<<endl;else{cout<<-1<<endl;}}else{cout<<-1<<endl;}}return 0;
}inline void getInt(int* p) {char ch;do {ch = getchar();} while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 + ch - '0';}}
}

转载于:https://www.cnblogs.com/qieqiemin/p/10666742.html

Less or Equal CodeForces - 977C (sort+细节)相关推荐

  1. CodeForces - Insertion Sort(打表找规律)

    题目链接:http://codeforces.com/gym/101955/problem/C Time limit:6.0 s Memory limit:1024 MB Problem Descri ...

  2. java数组给名字排序_用Java给数组排序

    public class BubbleDemo { public static void main(String[] args) { int arr[]={1,3,5,7,2,4,6,8,9}; bu ...

  3. The Unique MST 判断生成树是否唯一

    The Unique MST 题目抽象:给你一个连通无向网,判断生成树是否唯一. 分析 :判定最小生成树是否唯一的一个正确思路为: 1) 对图中每条边,扫描其他边,如果存在相同权值的边,则对该边作标记 ...

  4. 求同存异【Java】

    题目描述 输入两个数组(数组元素个数6和8),输出在两个数组中都出现的元素(如a[6]={2,3,4,5,6,7},b[8]={3,5,7,9,11,13,15,19},则输出3.5.7). 输入描述 ...

  5. 扑克牌顺子 算法 php,算法-扑克牌顺子详解

    /* [扑克牌顺子] [题目] 一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张). 随机从中抽出了5张牌, 看看能不能抽到顺子,其中大小王可以变成任意数字. A看作1,J为11,Q为 ...

  6. 【Codeforces】659B Qualifying Contest (sort)

    http://codeforces.com/problemset/problem/659/B n个人,m个地区,选出每个地区分数最高的两个人 下面有n行,每一行的第一个数表示姓名,第二个数是地区的序号 ...

  7. [CodeForces 892A] Greed (Java中sort实现从大到小排序)

    题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...

  8. Codeforces Round #732 (Div. 2) C. AquaMoon and Strange Sort 思维

    传送门 文章目录 题意: 思路: 题意: 给你nnn个数,每个数初始方向是向右,每次可以交换相邻两个位置并且将这两个位置的方向调换,问这个序列的最终状态能否是非递减且方向都向右. n≤1e5,ai≤1 ...

  9. Codeforces Round #592 (Div. 2) F. Chips 构造 + 细节

    传送门 文章目录 题意: 思路: 题意: 思路: 恶心的构造题,思路很简单但是代码细节很多,搞了半天. 根据题目的性质不难发现,如果有两个相同颜色的球相邻,那么他们的颜色永远不会改变. 根据这个性质, ...

  10. 【CodeForces - 988C 】Equal Sums (思维,STLmap,STLset,tricks)

    题干: You are given kk sequences of integers. The length of the ii-th sequence equals to nini. You hav ...

最新文章

  1. php禁止伪造_php防止伪造的数据从URL提交方法
  2. 并发编程(CountDownLatch使用)
  3. Django startproject的问题
  4. armv8的Serror的理解
  5. Spring集成web环境(使用封装好的工具)
  6. 用camelot读取表格_如何使用Camelot从PDF提取表格
  7. matlab 小波中心频率,小波频域特性Matlab实现.pdf
  8. 技术案例分享:WIPTEC采用Aruba边缘服务平台,实现物流配送生产自动化、精简生产力
  9. JAVA设计模式 - 建造者模式
  10. 【DataMagic】如何在万亿级别规模的数据量上使用Spark
  11. python发音模块-python 利用pyttsx3文字转语音过程详解
  12. android上对cookie的读写操作,Android上对Cookie的读写操作(附Demo)
  13. 新手入门Java疯狂讲义遇到的100个问题
  14. mysql开启远程登录
  15. Acmer--弱水三千,只取一瓢
  16. 计算机存储单元ASCI,在计算机存储器中,存储英文字母\quot;A\quot;时,存储的是它的( ) A.输入码B.ASCII码C - 作业在线问答...
  17. 这是一个全民销售的时代
  18. Android可上下左右滑动的列表
  19. jpype踩的那些坑
  20. P4 程序设计语法学习

热门文章

  1. 某生鲜平台面试题:如何保证库存在高并发的场景下是安全的?
  2. 架构师进阶:Linux进程间如何共享内存?
  3. 状态管理模式 — Vuex如何使用?
  4. Android之Retrofit详解(转载)
  5. 4412 学习目录总结
  6. Visual Studio Code 配合 Node.js 轻松实现JS断点调试
  7. 操作系统-页式虚拟存储器管理系统设计
  8. UVa232.Crossword Answers
  9. Web.config中用customErrors可以自定义默认的出错页面
  10. 获取 SQL Server 版本号