Less or Equal
注意边角
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相关推荐
- java equal hashcode_Java(二)equal 和 hashcode使用
一.hashCode()和equals()是什么? hashCode()方法和equals()方法的作用其实一样,在Java里都是用来对比两个对象是否相等一致. Equal 没有重写的equal 使用 ...
- 讨论JDK的File.equal()
我们一般比较两个文件中的对象是相同的文件,通常使用java.io.File.equal().这里,equal()是不是文件内容的比较结果为.象是否指向同一个文件. File的equal()方法.实际上 ...
- 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 ...
- 语义分割--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 本文针 ...
- logic:equal 标签的使用(转)
<logic:equal name="music" property="distrubute" value="true"> ...
- 记录由Equal基础知识引起的内存泄露
在最近的公司框架开发中,利用了网上某大牛的反射缓存库作为辅助.在测试的时候发现出现了巨大的内存泄露,在频繁的操作后,内存不断的产生巨大的开销,10多分钟就占有了5,6m的内存.解决问题的时,公司不能上 ...
- 无法解决 equal to 操作中 SQL_Latin1_General_CP1_CI_AS 和 Chinese_PRC_CI_AS 之间的排序规则冲突。...
一个旧有系统需要从另一个新系统获取数据.由于两个系统数据库的的排序规规则不同.在存储过程中SELECT数据时,引发了"无法解决 equal to 操作中 "SQL_Latin1_G ...
- LeetCode Minimum Moves to Equal Array Elements II
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...
- C#中的==、Equal、ReferenceEqual(转载)
1. ReferenceEquals, == , Equals Equals , == , ReferenceEquals都可以用于判断两个对象的个体是不是相等. a) ReferenceEqual ...
- 【Vegas原创】“無法解析 equal to 動作的定序衝突”错误的处理
错误:無法解析 equal to 動作的定序衝突. COLLATE Chinese_Taiwan_Stroke_CI_AS 用法: select @EMP_ID=emp_id from am_empl ...
最新文章
- 记录一下matlab-vs联合编程
- C# 容器重用避免GC 的论证
- 优化案例(part3)--Aberrance suppresse dspatio-temporal correlation filters for visual object tracking
- linux的常用操作——压缩和解压缩
- 运用Axure6.5快速完成微信交互效果的简单办法
- Visual Studio 2012 Update 4 RC 启动调试失败解决方案
- spring:注解配置AOP
- 字体转换,woff,ttf,otf,eot,svg
- 【Android】我用 ARCore 做了一个 1:1 的高达
- VIsualSVNSever 和SVN安装教程
- Map集合简单应用的例子(世界杯)
- java的8年来工作汇总
- POJ-2524 Ubiquitous Religions
- 新一代Hive客户端工具:Beeline
- 商家冷启难题,快手每天8亿流量能解决吗?
- AI 人工智能学习路线
- 翻译《CSS权威指南》第3版第1章有感
- QuartusII仿真通过但上板验证不过
- 微信公众号-自动聊天机器人
- Myeclipse报的是严重: Socketaccept failed