注意边角
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;10e9] (i.e. 1≤x≤10e9) 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 n and k (1≤n≤2⋅10e5, 0≤k≤n). The second line of the input contains nn integer numbers a1,a2,…,ana1,a2,…,an (1≤ai≤10e9) — the sequence itself.
output
Print any integer number xx from range [1;10e9]such that exactly k elements of given sequence is less or equal to x.

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

#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int m[N];
int main(){int n,k;cin>>n>>k;for(int i=1;i<=n;i++)cin>>m[i];sort(m+1,m+1+n);if(n==k)cout<<m[n];else if(k==0){if(m[1]==1)puts("-1");else puts("1");}else if(m[k]==m[k+1])puts("-1");else cout<<m[k]<<endl;
}

因为codeforces炸了,所以以上代码现场手打,有错请谅解

Less or Equal相关推荐

  1. java equal hashcode_Java(二)equal 和 hashcode使用

    一.hashCode()和equals()是什么? hashCode()方法和equals()方法的作用其实一样,在Java里都是用来对比两个对象是否相等一致. Equal 没有重写的equal 使用 ...

  2. 讨论JDK的File.equal()

    我们一般比较两个文件中的对象是相同的文件,通常使用java.io.File.equal().这里,equal()是不是文件内容的比较结果为.象是否指向同一个文件. File的equal()方法.实际上 ...

  3. RuntimeError: each element in list of batch should be of equal size

    RuntimeError: each element in list of batch should be of equal size 示例代码: import os import re from t ...

  4. 语义分割--Not All Pixels Are Equal:Difficulty-Aware Semantic Segmentation via Deep Layer Cascade

    Not All Pixels Are Equal: Difficulty-Aware Semantic Segmentation via Deep Layer Cascade CVPR2017 本文针 ...

  5. logic:equal 标签的使用(转)

    <logic:equal name="music" property="distrubute" value="true">    ...

  6. 记录由Equal基础知识引起的内存泄露

    在最近的公司框架开发中,利用了网上某大牛的反射缓存库作为辅助.在测试的时候发现出现了巨大的内存泄露,在频繁的操作后,内存不断的产生巨大的开销,10多分钟就占有了5,6m的内存.解决问题的时,公司不能上 ...

  7. 无法解决 equal to 操作中 SQL_Latin1_General_CP1_CI_AS 和 Chinese_PRC_CI_AS 之间的排序规则冲突。...

    一个旧有系统需要从另一个新系统获取数据.由于两个系统数据库的的排序规规则不同.在存储过程中SELECT数据时,引发了"无法解决 equal to 操作中 "SQL_Latin1_G ...

  8. LeetCode Minimum Moves to Equal Array Elements II

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...

  9. C#中的==、Equal、ReferenceEqual(转载)

    1. ReferenceEquals, == , Equals  Equals , == , ReferenceEquals都可以用于判断两个对象的个体是不是相等. a) ReferenceEqual ...

  10. 【Vegas原创】“無法解析 equal to 動作的定序衝突”错误的处理

    错误:無法解析 equal to 動作的定序衝突. COLLATE Chinese_Taiwan_Stroke_CI_AS 用法: select @EMP_ID=emp_id from am_empl ...

最新文章

  1. 记录一下matlab-vs联合编程
  2. C# 容器重用避免GC 的论证
  3. 优化案例(part3)--Aberrance suppresse dspatio-temporal correlation filters for visual object tracking
  4. linux的常用操作——压缩和解压缩
  5. 运用Axure6.5快速完成微信交互效果的简单办法
  6. Visual Studio 2012 Update 4 RC 启动调试失败解决方案
  7. spring:注解配置AOP
  8. 字体转换,woff,ttf,otf,eot,svg
  9. 【Android】我用 ARCore 做了一个 1:1 的高达
  10. VIsualSVNSever 和SVN安装教程
  11. Map集合简单应用的例子(世界杯)
  12. java的8年来工作汇总
  13. POJ-2524 Ubiquitous Religions
  14. 新一代Hive客户端工具:Beeline
  15. 商家冷启难题,快手每天8亿流量能解决吗?
  16. AI 人工智能学习路线
  17. 翻译《CSS权威指南》第3版第1章有感
  18. QuartusII仿真通过但上板验证不过
  19. 微信公众号-自动聊天机器人
  20. Myeclipse报的是严重: Socketaccept failed

热门文章

  1. 新装win10系统的桌面没有“我的电脑”图标解决办法
  2. QGC地面站小白安装与简单实用
  3. jmeter二次开发——阶梯式/分步式压测聚合报告定制化显示
  4. 2021年焊工(技师)考试题库及焊工(技师)考试报名
  5. 怎么聊微信才能让她喜欢你
  6. python微信聊天
  7. discuz 发表带html内容的帖子
  8. android开发百度地图定位到大西洋去了!!
  9. 计算机软件神奇合集【强大工具】
  10. 关于Android中的位置服务解读