All problems

Problem 883

Kth Smallest Prime Fraction

Medium · 20 pts · Array, Binary Search, Heap

Problem

The sorted array contains 1 and distinct prime numbers. For every pair of positions i < j, form the fraction ARR[i] / ARR[j]. Print the K-th smallest of these fractions as its numerator and denominator. Compare fractions exactly with cross multiplication. A min-heap that starts with ARR[0] / ARR[j] for every j and repeatedly replaces the popped fraction by the next numerator gives the answer in O(K log N).

Input

The first line contains N and K. The second line contains the N sorted values (1 followed by distinct primes).

Output

Print the numerator and denominator of the K-th smallest fraction, separated by a space.

Constraints

2 <= N <= 1000; ARR[0] = 1; the other values are distinct primes below 30000; 1 <= K <= N × (N - 1) / 2

Example input

4 3
1 2 3 5

Example output

2 5

Explanation

For 1 2 3 5 the fractions in order are 1/5, 1/3, 2/5, 1/2, 3/5 and 2/3. The third smallest is 2/5, so the answer is 2 5.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Divide Chocolate Next: Search in a Mountain Array