codeforces 161 Div2 B

B. Squares
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has found a piece of paper with a coordinate system written on it. There are n distinct 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 nk (1 ≤ n, k ≤ 50). The second line contains space-separated integersa1, 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 ksquares. If there are multiple answers, you are allowed to print any of them.

If there is no answer, print "-1" (without the quotes).

Sample test(s)
input
4 3
5 1 3 4
output
2 1
input
3 1
2 4 1
output
4 0
input
4 50
5 1 10 2
output
-1

对ai排序后从大到小数 即可

附代码:
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 int cmp(const void *a,const void *b)
 5 {
 6     return *(int *)b-*(int *)a;
 7 }
 8 
 9 int arr[50]={0};
10 
11 int main(void)
12 {
13     int n, k, number, status=0;
14     int i;
15     scanf("%d %d", &n, &k);
16     for( i=0; i<n; i++)
17         scanf("%d", &arr[i]);
18 
19     qsort( arr, n, sizeof(int), cmp);
20     for( i=1; i<=k; i++)
21     {
22         if( i>n)
23         {
24             i=n;
25             status=1;
26             break;
27         }
28     }
29     i--;
30     if( status)
31         printf("-1\n");
32     else
33         printf("%d 0\n", arr[i-1]);
34 
35     return 0;
36 }

 

转载于:https://www.cnblogs.com/shadow-justice/archive/2013/01/17/2865460.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值