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的更多相关文章
随机推荐
- Maven学习第4期---Maven简单使用
一.Maven常用命令 在学习使用Maven构建项目之前,先来了解一下Maven一些实用的命令.mvn的命令有很多,在项目开发中,理解了下面的几个常用命令后,运用maven就基本没有问题了.Maven ...
- 每秒高达1.6亿次操作的并发键值存储库 FASTER 诞生
FASTER 在过去十年中,云中的数据密集型应用程序和服务有了巨大的增长.数据在各种边设施(例如,设备,浏览器和服务器)上创建,并由云应用程序处理用来获得数据价值或做出决策.应用程序和服务可以处理收集 ...
- Node.js api接口和SQL数据库关联
数据库表创建 服务器环境配置.连接 .操作.数据库 API接口 原则:
- pycharm 中 import requests 报错
一 , 使用Pycharm来抓取网页的时候,要导入requests模块,但是在pycharm中 import requests 报错. 原因: python中还没有安装requests库 解决办法: ...
- iOS-拍照后裁剪,不可拖动照片的问题
2016.07.08 15:04* 字数 1837 阅读 6066评论 6喜欢 26赞赏 1 问题 在项目中,选择照片或拍照的功能很长见,由于我之前采用系统自带的UIimagePickViewCont ...
- MySQLl导入导出SQL文件
window 1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u dbuser -p dbname > dbname.sql ...
- 项目集成自动分词系统ansj,实现自定义词库
一,分词系统地址:https://github.com/NLPchina/ansj_seg 二,为什么选择ansj? 1.项目需求: 我们平台要做手机售后的舆情分析,即对购买手机的用户的评论进行分析. ...
- Access使用记录
iif函数 此函数类似编程语言中的双目运算符,官方解释如下: 在任何可以使用表达式的位置均可使用 IIf.您可以使用 IIf 确定另一个表达式为 True 还是 False.如果表达式为 True,则 ...
- jmeter内存溢出解决办法
原文:http://blog.51cto.com/xqtesting/2107927 使用jmeter进行压力测试时遇到一段时间后报内存溢出outfmenmory错误,导致jmeter卡死了,先尝试在 ...
- python读取文件内的IP信息 练习
代码如下: #导包 import fileinput import re def readArw(): for line in fileinput.input(r"G:/raw.txt&qu ...