No.3073 Fraction Median
タグ : / 解いたユーザー数 66
作問者 : 👑
hamamu
Problem Statement
You are given $N$ positive integers $A_1, A_2, \dots, A_N$.
Consider choosing a pair of distinct integers $(i, j)$ satisfying $1 \leq i, j \leq N$. There are $N(N - 1)$ ways to make this choice. Considering $\dfrac{A_i}{A_j}$ for each of them, find the $\dfrac{N(N-1)}{2}$-th smallest value.
The answer can be expressed as $\dfrac{x}{y}$ using coprime positive integers $x, y$. Output these $x, y$.
Constraints
- All input values are integers
- $2 \leq N \leq 1.5 \times 10^6$
- $1 \leq A_i \leq 10^9$
Input
The input is given from standard input in the following format.
$N$ $A_1$ $A_2$ $\dots$ $A_N$
Since the input can be large, using a fast input method is recommended.
Output
When the answer is expressed as $\dfrac{x}{y}$ using coprime positive integers $x, y$, output $x, y$ in this order, separated by a space.
Sample
Sample 1
Input
4 1 3 5 6
Output
5 6
Listing the $6$ smallest values of $\dfrac{A_i}{A_j}$ in ascending order gives $\dfrac{1}{6}, \dfrac{1}{5}, \dfrac{1}{3}, \dfrac{3}{6}, \dfrac{3}{5}, \dfrac{5}{6}$.
Therefore, the $6$-th smallest value of $\dfrac{A_i}{A_j}$ is $\dfrac{5}{6}$, so output $5, 6$ in this order, separated by a space.
Sample 2
Input
5 10 10 10 10 10
Output
1 1
All values of $\dfrac{A_i}{A_j}$ are $1$, so output 1 1.
Note that $x, y$ must be coprime. Therefore, an output such as 10 10, for example, will be judged as incorrect.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。