B. squares

Source: Internet
Author: User
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 areNDistinct squares drawn in this coordinate system. Let's
Number the squares with integers from 1N. It turned out that points with coordinates (0, defaults 0) and (AI, Bytes,AI) Are
The opposite corners ofI-Th square.

Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactlyKDrawn squares. We'll say that
Point belongs to a square, if the point is located either inside the square, or on its boundary.

Help Vasya find a point that wocould meet the described limits.

Input

The first line contains two space-separated IntegersN,K(1 digit ≤ DigitN, Bytes,KLimit ≤ limit 50 ).
The second line contains space-separated IntegersA1, bytes,A2, middle..., middle ,...,AN(1 digit ≤ DigitAILimit ≤ limit 109 ).

It is guaranteed that all given squares are distinct.

Output

In a single line print two space-separated IntegersXAndY(0 bytes ≤ bytesX, Bytes,YLimit ≤ limit 109 )-
The coordinates of the point that belongs to exactlyKSquares. 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 35 1 3 4
Output
2 1
Input
3 12 4 1
Output
4 0
Input
4 505 1 10 2
Output
-1

Solution Description: This question is actually a Nesting Problem of N squares, the vertices in the k-th region are actually the vertices in the area of the square with the k-th largest (excluding vertices in the area smaller than the k-th), as shown in, if K is 2, it is to find the point of the Second Large Square, the internal point, and the boundary can all be. Because any point in the question can be used, we can take the vertex completely for simplicity, that is (4, 4. The final question is sorted by the number of columns, and the output number is K (K is smaller than N), otherwise it is-1.

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){int n,k,i,j;int a[51];int temp1;scanf("%d %d",&n,&k);for(i=0;i<n;i++){scanf("%d",&a[i]);}if(k>n){printf("-1\n");}else{for(i=0;i<n;i++){for(j=i+1;j<n;j++){if(a[j]>a[i]){temp1=a[i];a[i]=a[j];a[j]=temp1;}}}printf("%d %d\n",a[k-1],a[k-1]);}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.