CF160C.Find Pair

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing n (not necessarily different) integers _a_1, _a_2, ..., a__n. We are interested in all possible pairs of numbers (a__i, a__j), (1 ≤ i, j ≤ n). In other words, let's consider all _n_2 pairs of numbers, picked from the given array.

For example, in sequence a = {3, 1, 5} are 9 pairs of numbers: (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 (_p_1, _q_1) is lexicographically less than pair (_p_2, _q_2) only if either _p_1 < _p_2, or _p_1 = _p_2 and _q_1 < _q_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)

Let's number all the pair in the sorted list from 1 to _n_2. Your task is formulated like this: you should find the k-th pair in the ordered list of all possible pairs of the array you've been given.

你又遇到了一个关于数组的问题。考虑一个任意的序列,其中包含 nn 个(不一定互不相同)整数 a1,a2,…,ana_1, a_2, \dots, a_n。我们关注所有可能的数对 (ai,aj)(a_i, a_j),其中 1≤i,j≤n1 \le i, j \le n。换言之,考虑从给定数组中任取两个数(可重复、可相同位置)所形成的所有 n2n^2 个数对。

例如,在序列 a={3,1,5}a = \{3, 1, 5\} 中,共有 9 个数对:(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)。

现在将所有这些数对按字典序非降序排序。回忆一下:数对 (p1,q1)(p_1, q_1) 在字典序下严格小于 (p2,q2)(p_2, q_2),当且仅当 p1<p2p_1 < p_2,或者 p1=p2p_1 = p_2 且 q1<q2q_1 < q_2。

那么,上述例子中的数对将被排序为:(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)。

我们将排序后列表中的所有数对从 11 编号至 n2n^2。你的任务是:在给定数组所产生的所有可能数对的有序列表中,找出第 kk 个数对。

输入格式

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ _n_2). The second line contains the array containing n integers _a_1, _a_2, ..., a__n ( - 109 ≤ a__i ≤ 109). 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.

第一行包含两个整数 nn 和 kk(1≤n≤1051 \leq n \leq 10^5,1≤k≤n21 \leq k \leq n^2)。第二行包含一个由 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n 组成的数组(−109≤ai≤109-10^9 \leq a_i \leq 10^9)。数组中的数字可以重复。所有数字以空格分隔。

在 C++ 中,请勿使用 %lld 格式说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 格式说明符。

输出格式

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

在单行中输出两个数——所求的第 k 个数对。

输入输出样例

  • 输入#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). The 4-th of them is pair (2, 2).

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

在第一个样例中,给定数组的排序序列为:(1, 1), (1, 2), (2, 1), (2, 2)(1,\,1),\,(1,\,2),\,(2,\,1),\,(2,\,2)。其中第 44 个元素为数对 (2, 2)(2,\,2)。

第二个样例中数组的排序序列已在题目陈述中给出。其中第 22 个数对为 (1, 3)(1,\,3)。

输入解题思路,AI测评打分。不知道怎么写?

首页