codeforces263B
Squares
Vasya has found a piece of paper with a coordinate system written on it. There are ndistinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai)are the opposite corners of the i-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
Input
The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
It is guaranteed that all given squares are distinct.
Output
In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Examples
4 3
5 1 3 4
2 1
3 1
2 4 1
4 0
4 50
5 1 10 2
-1 sol:排序之后倒序往回找K个,找到n-K+1个正方形,一维坐标是它的边长,还有一维是0,这样一定是可以的
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,K,a[N];
int main()
{
int i;
R(n); R(K);
for(i=;i<=n;i++) R(a[i]);
if(K>n) return *puts("-1");
sort(a+,a+n+);
W(a[n-K+]); Wl();
return ;
}
codeforces263B的更多相关文章
随机推荐
- 串行FLASH文件系统FatFs---转自野火论坛
为了支持长文件名,需要用到FATFS源码中的cc936.c的两个函数ff_convert,ff_wtoupper:这里面直接用了两个大数组(127KB)来做unicode转gbk(OEM)的对照表,这 ...
- DOM(一)
DOM可以将任何HMLT或XML文档描绘成一个由多层节点构成的结构,节点氛围几种不同的类型,每种类型分别表示文档中不同的信息及标记,每个节点都拥有各自的特点.数据和方法. Node类型 DOM1级定义 ...
- 吉特日化MES-日化生产称料基本步骤
在日化行业称料是一个非常重要的环节,整个生产过程中称料所占据的时间也比较长,特别是遇到对料体精度高,量大的情况下称料都比较困难,汇总一下人工称料的基本过程: (1) 称量任务准备:根据生产工单或者生产 ...
- OdnShop 发布 V1.0 正式版,完整可用的开源微商城系统
OdnShop是基于ASP.NET 4.0+Mysql开发的开源微商城系统,我们的目标是构建一个核心完善而又轻量级的微商城平台. 本版本更新功能: 1,修正数据库操作的部分表名称的表前缀错误: 2,修 ...
- Python中的鸡肋多线程
作者:DarrenChan陈驰链接:https://www.zhihu.com/question/23474039/answer/269526476来源:知乎著作权归作者所有.商业转载请联系作者获得授 ...
- mysql触发器,视图,游标
什么事触发器: 触发器是一中特殊的存储过程,主要是通过事件来触发而被执行的.它可以强化约束,来维护数据的完整性和一致性,可以跟踪数据库内的操作从而不允许未经许可的更新和变化.可以联级运算.如,某表上的 ...
- redis 的使用,及如何使用redis维护数亿人的登录状态
一.redis中几个常用的方法 redis的使用场景移步本文 select db redis 下默认有有16个表,0~15可以通过:select 2 或者 select 11这样的方式切换表 keys ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bw.mapper.BillMapper.getBillList at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:225
这个错误是没有找到映射文件 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.b ...
- java总结:double取两位小数的多种方法
1.方法一 四舍五入: import java.math.BigDecimal; double f = 111231.5585; BigDecimal b = new BigDecimal(f); d ...
- 使用PHPExcel导出数据库表结构及内容
导出表结构: mysql> desc user ; +----------+--------------+------+-----+---------------------+--------- ...