Problem Description

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

Note that the sequence can contain equal elements.

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

Input

The first line of the input contains integer numbers nn and kk (1≤n≤2⋅10^5, 0≤k≤n). The second line of the input contains n integer numbers a1,a2,…,an (1≤ai≤10^9) — the sequence itself.

Output

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

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

Examples

Input

7 4
3 7 5 1 10 3 20

Output

6

Input

7 2
3 7 5 1 10 3 20

Output

-1

题意: 给出 n 个数,求是否存在一个整数使得这个 n 个数中的 k 个数小于或等于这个整数,如果有这个整数,输出这个整数,如果没有,输出 -1

思路:一开始以为用 sort 排序后直接输出第 k 个即可,后来发现没这么简单,当 k 大于 1 或小于 n 时是可以的,但当 k 等于 1 或等于 n 时,情况就不同了,因此在 n 个数两端,根据要求的[1,1e9],加上一个最大值与最小值,再 sort 排序即可。

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 1000005
#define MOD 1e9+7
#define E 1e-6
typedef long long ll;
using namespace std;
int a[N];
int main()
{int n,k;cin>>n>>k;for(int i=1;i<=n;i++)cin>>a[i];a[0]=1;sort(a,a+n+1);a[n+2]=INF;if(a[k]==a[k+1])cout<<-1<<endl;elsecout<<a[k]<<endl;return 0;
}

Less or Equal(CF-977C)相关推荐

  1. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  2. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  3. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  4. D. Make a Power of Two(cf#739DIV3)

    D. Make a Power of Two 链接: link. 题意: 找出将数字转换为 2 的任意幂的最小移动次数. 题解: 先将2的xxx次幂的结果以字符串形式保存,输入字符串nnn后,因为存在 ...

  5. Web of Lies(CF 1548A)

    这是今天在打个人赛时碰见的一道题,是一道半图论半思维的题. Web of Lies 题目大意不难理解,在这里只需要注意一些细节.在加边时,只有当cnt[min]的值为1时答案才应该减1,而不是当cnt ...

  6. 【解题报告】博弈专场 (CF 2000~2200)前五题

    [解题报告]博弈专场 (CF 2000+)前五题 A:Fox and Card Game | CF388C 题意 思路 代码 B:Berzerk | CF786A 题意 思路 代码 C:Ithea P ...

  7. 软件设计师提纲+复习资料整理(上午题)

    文章目录 软件设计师考试大纲 上午题(选择题) 一.计算机组成原理 考点:CPU结构组成 考点:原码.反码.补码定点整数范围 考点:浮点数表示 考点:RISC和CISC计算机的区别 考点:奇校验与偶校 ...

  8. SpringBoot(模板Thymeleaf)

    模板Thymeleaf 相关配置: <dependency> <groupId>org.springframework.boot</groupId> <art ...

  9. c性能大容量cket_5千左右预算,既轻薄(高颜值)又高性能的笔记本推荐(畅玩LOL、CF、DNF、流放之路、梦幻西游)...

    在目前笔记本制造技术中,轻薄和性能二者不可兼得,轻薄的本性能不高,高性能的太厚重, 这里推荐一些既轻薄,外观好看,同时又高性能的轻薄本. 很多轻薄本多为低压U+集成显卡,性能太弱,都不适合玩大型3D网 ...

  10. 基于矩阵分解的CF算法实现(一):(Funk SVD)LFM

    基于矩阵分解的CF算法实现(一):LFM LFM也就是前面提到的Funk SVD矩阵分解 LFM原理解析 LFM(latent factor model)隐语义模型核心思想是通过隐含特征联系用户和物品 ...

最新文章

  1. TCRP风控管理师知识点:信贷评分卡模型授信
  2. C++ pair类模板
  3. 关于推送系统设计的一些总结与思考(二)
  4. yolo如何降低loss_你一定从未看过如此通俗易懂的YOLO系列(从v1到v5)模型解读 (上)...
  5. 【高并发】JUC中的Executor框架详解2
  6. 这款Java性能调优工具,真的很强!
  7. 网络安全相关行业必备网站
  8. Python面向对象之结构与成员
  9. 网络研讨会的邀请:SQL优化:你不是一个人在战斗
  10. js 利用数组队列模拟多线程操作
  11. Windows XP Home Edition安裝 IIS 的方法
  12. iOS开发之Xcode常见错误
  13. sql*loader
  14. OC 教程 极光推送
  15. 报表工具九个核心标准
  16. 改ip 银河麒麟_PK体系银河麒麟云桌面和云平台
  17. 安装kata container with cri-o
  18. 去除PDF文件中的斜体文字水印
  19. JS获取当前时间是否为节假日,周末
  20. 王和勇计算机软件,图像空间中的鉴别型局部线性嵌入方法

热门文章

  1. 为什么说去中心化很重要
  2. 按home键退出的activity可以不进入stop模式码_用了几年的iPhone,竟然不知道苹果手机还有“游戏模式”?...
  3. 了解这些坑,再也不会出现诡异的BUG了~
  4. 他一口气写出了这7k字的红黑树总结!看过的都说好!!|文末送书
  5. ABAP中的F4帮助怎么用
  6. SAP Java Connector(JCo)
  7. 关于oracle分组后组外排序的问题
  8. Linux系统:centos7下搭建ElasticSearch中间件,常用接口演示
  9. centos7.5 部署flask+nginx+uwsgi+python3
  10. Hibernate day01