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的更多相关文章
随机推荐
- Luogu P5168 xtq玩魔塔
这题不错啊,结合了一些不太传统的姿势. 首先看到题目有一问从一个点到另一个点边权最小值.想到了什么? 克鲁斯卡尔生成树+倍增?好吧其实有一个更常用NB的算法叫克鲁斯卡尔重构树 (不会的可以看dalao ...
- Jlink使用技巧之J-Scope虚拟示波器功能
J-Link简介 J-Link是SEGGER公司为支持仿真ARM内核芯片推出的JTAG仿真器.简单地说,是给一个JTAG协议转换盒.其连接到计算机用的是USB接口,而到目标板内部用的还是jtag协议. ...
- 使用docker Registry快速搭建私有镜像仓库
当我们执行docker pull xxx的时候,docker默认是从registry.docker.com这个地址上去查找我们所需要的镜像文件,然后执行下载操作.这类的镜像仓库就是docker默认的公 ...
- .net core 监听性能,异常
https://www.cnblogs.com/laozhang-is-phi/p/10287023.html#autoid-2-2-0
- tornado设置cookie并加密
最近看看tornado,遇到了sso的东西,了解下如何设置cookie 1.基本cookie set_cookie 方法在用户的浏览中设置 cookie: get_cookie 方法在用户的浏览中获取 ...
- hdu 5584 LCM Walk
没用运用好式子...想想其实很简单,首先应该分析,由于每次加一个LCM是大于等于其中任何一个数的,那么我LCM加在哪个数上面,那个数就是会变成大的,这样想,我们就知道,每个(x,y)对应就一种情况. ...
- 阿里云服务器使用镜像市场上的环境以后sql不能远程问题
关于阿里云的服务器,首先要说的就是买了以后是没有环境的,什么都需要自己配置,也是在这个上面栽了很多跟头最后去的镜像市场买的一个IIS8+SQL2016的asp.net环境 怎么说呢,感觉有些问题的本源 ...
- Django ORM 反向查询
一/一对多反向查询 先定义两个模型,一个是A,一个是B,是一对多的类型. class A(models.Model): name= models.CharField('名称', max_lengt ...
- Python_线程、线程效率测试、数据隔离测试、主线程和子线程
0.进程中的概念 三状态:就绪.运行.阻塞 就绪(Ready):当进程已分配到除CPU以外的所有必要资源,只要获得处理机便可立即执行,这时的进程状态成为就绪状态. 执行/运行(Running)状态:当 ...
- 后台管理系统之系统操作日志开发(Java实现)
一,功能点 实现管理员操作数据的记录.效果如下 二,代码实现 基于注解的Aop日志记录 1.Log实体类 package com.ideal.manage.guest.bean.log; import ...