CF160C.Find Pair

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing nn (not necessarily different) integers a1a_{1} , a2a_{2} , ..., ana_{n} . We are interested in all possible pairs of numbers ( aia_{i} , aja_{j} ), ( 1<=i,j<=n1<=i,j<=n ). In other words, let's consider all n2n^{2} pairs of numbers, picked from the given array.

For example, in sequence a=3,1,5a={3,1,5} are 99 pairs of numbers: (3,3),(3,1),(3,5),(1,3),(1,1),(1,5),(5,3),(5,1),(5,5)(3,3),(3,1),(3,5),(1,3),(1,1),(1,5),(5,3),(5,1),(5,5) .

Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair ( p1p_{1} , q1q_{1} ) is lexicographically less than pair ( p2p_{2} , q2q_{2} ) only if either p1p_{1} < p2p_{2} , or p1p_{1} = p2p_{2} and q1q_{1} < q2q_{2} .

Then the sequence, mentioned above, will be sorted like that: (1,1),(1,3),(1,5),(3,1),(3,3),(3,5),(5,1),(5,3),(5,5)(1,1),(1,3),(1,5),(3,1),(3,3),(3,5),(5,1),(5,3),(5,5)

Let's number all the pair in the sorted list from 11 to n2n^{2} . Your task is formulated like this: you should find the kk -th pair in the ordered list of all possible pairs of the array you've been given.

输入格式

The first line contains two integers nn and kk ( 1<=n<=105,1<=k<=n21<=n<=10^{5},1<=k<=n^{2} ). The second line contains the array containing nn integers a1a_{1} , a2a_{2} , ..., ana_{n} ( 109<=ai<=109-10^{9}<=a_{i}<=10^{9} ). The numbers in the array can coincide. All numbers are separated with spaces.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout, streams or the %I64d specificator instead.

输出格式

In the single line print two numbers — the sought kk -th pair.

输入输出样例

  • 输入#1

    2 4
    2 1
    

    输出#1

    2 2
    
  • 输入#2

    3 2
    3 1 5
    

    输出#2

    1 3
    

说明/提示

In the first sample the sorted sequence for the given array looks as: (1,1),(1,2),(2,1),(2,2)(1,1),(1,2),(2,1),(2,2) . The 44 -th of them is pair (2,2)(2,2) .

The sorted sequence for the array from the second sample is given in the statement. The 22 -nd pair there is (1,3)(1,3) .

首页