English · Original
Chinese · Translation
Formal · Original
You have $n$ sticks of the given lengths.
Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be formed by a single stick. No stick can be chosen multiple times. It is guaranteed that it is always possible to choose such sticks.
Let $S$ be the area of the rectangle and $P$ be the perimeter of the rectangle.
The chosen rectangle should have the value $\frac{P^2}{S}$ minimal possible. The value is taken without any rounding.
If there are multiple answers, print any of them.
Each testcase contains several lists of sticks, for each of them you are required to solve the problem separately.
## Input
The first line contains a single integer $T$ ($T \ge 1$) — the number of lists of sticks in the testcase.
Then $2T$ lines follow — lines $(2i - 1)$ and $2i$ of them describe the $i$\-th list. The first line of the pair contains a single integer $n$ ($4 \le n \le 10^6$) — the number of sticks in the $i$\-th list. The second line of the pair contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_j \le 10^4$) — lengths of the sticks in the $i$\-th list.
It is guaranteed that for each list there exists a way to choose four sticks so that they form a rectangle.
The total number of sticks in all $T$ lists doesn't exceed $10^6$ in each testcase.
## Output
Print $T$ lines. The $i$\-th line should contain the answer to the $i$\-th list of the input. That is the lengths of the four sticks you choose from the $i$\-th list, so that they form a rectangle and the value $\frac{P^2}{S}$ of this rectangle is minimal possible. You can print these four lengths in arbitrary order.
If there are multiple answers, print any of them.
[samples]
## Note
There is only one way to choose four sticks in the first list, they form a rectangle with sides $2$ and $7$, its area is $2 \cdot 7 = 14$, perimeter is $2(2 + 7) = 18$. $\frac{18^2}{14} \approx 23.143$.
The second list contains subsets of four sticks that can form rectangles with sides $(1, 2)$, $(2, 8)$ and $(1, 8)$. Their values are $\frac{6^2}{2} = 18$, $\frac{20^2}{16} = 25$ and $\frac{18^2}{8} = 40.5$, respectively. The minimal one of them is the rectangle $(1, 2)$.
You can choose any four of the $5$ given sticks from the third list, they will form a square with side $5$, which is still a rectangle with sides $(5, 5)$.
你有 $n$ 根长度给定的木棍。
你的任务是从中恰好选出四根,使得它们能构成一个矩形。不允许将任何木棍切割,矩形的每条边必须由一根完整的木棍构成,且每根木棍只能被选择一次。题目保证总能选出这样的四根木棍。
设 $S$ 为矩形的面积,$P$ 为矩形的周长。
所选矩形应使值 $\frac{P^2}{S}$ 尽可能小。该值不进行任何四舍五入。
如果有多个答案,输出任意一个即可。
每个测试用例包含多个木棍列表,你需要对每个列表分别求解。
第一行包含一个整数 $T$($T \geq 1$)——测试用例中木棍列表的数量。
接下来有 $2T$ 行,其中第 $(2i - 1)$ 行和第 $2i$ 行描述第 $i$ 个列表。每对中的第一行包含一个整数 $n$($4 \leq n \leq 10^6$)——第 $i$ 个列表中木棍的数量;第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \leq a_j \leq 10^4$)——第 $i$ 个列表中各木棍的长度。
题目保证每个列表都存在一种方式,能选出四根木棍构成矩形。
所有 $T$ 个列表中的木棍总数在每个测试用例中不超过 $10^6$。
请输出 $T$ 行。第 $i$ 行应包含第 $i$ 个列表的答案,即从该列表中选出的四根木棍的长度,使得它们构成矩形,且该矩形的 $\frac{P^2}{S}$ 值最小。你可以按任意顺序输出这四个长度。
如果有多个答案,输出任意一个即可。
第一个列表中只有一种选择四根木棍的方式,它们构成边长为 $2$ 和 $7$ 的矩形,面积为 $2 \cdot 7 = 14$,周长为 $2 \cdot (2 + 7) = 18$,$\frac{18^2}{14} \approx 23.143$。
第二个列表中,存在能构成边长为 $(1, 2)$、$(2, 8)$ 和 $(1, 8)$ 的矩形的四根木棍子集。它们对应的值分别为 $\frac{6^2}{2} = 18$、$\frac{20^2}{16} = 25$ 和 $\frac{18^2}{8} = 40.5$,其中最小的是矩形 $(1, 2)$。
你可以从第三个列表的五根木棍中任选四根,它们将构成边长为 $5$ 的正方形,这仍然是一个边长为 $(5, 5)$ 的矩形。
## Input
第一行包含一个整数 $T$($T \geq 1$)——测试用例中木棍列表的数量。接下来有 $2T$ 行,其中第 $(2i - 1)$ 行和第 $2i$ 行描述第 $i$ 个列表。每对中的第一行包含一个整数 $n$($4 \leq n \leq 10^6$)——第 $i$ 个列表中木棍的数量;第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \leq a_j \leq 10^4$)——第 $i$ 个列表中各木棍的长度。题目保证每个列表都存在一种方式,能选出四根木棍构成矩形。所有 $T$ 个列表中的木棍总数在每个测试用例中不超过 $10^6$。
## Output
请输出 $T$ 行。第 $i$ 行应包含第 $i$ 个列表的答案,即从该列表中选出的四根木棍的长度,使得它们构成矩形,且该矩形的 $\frac{P^2}{S}$ 值最小。你可以按任意顺序输出这四个长度。如果有多个答案,输出任意一个即可。
[samples]
## Note
第一个列表中只有一种选择四根木棍的方式,它们构成边长为 $2$ 和 $7$ 的矩形,面积为 $2 \cdot 7 = 14$,周长为 $2 \cdot (2 + 7) = 18$,$\frac{18^2}{14} \approx 23.143$。第二个列表中,存在能构成边长为 $(1, 2)$、$(2, 8)$ 和 $(1, 8)$ 的矩形的四根木棍子集。它们对应的值分别为 $\frac{6^2}{2} = 18$、$\frac{20^2}{16} = 25$ 和 $\frac{18^2}{8} = 40.5$,其中最小的是矩形 $(1, 2)$。你可以从第三个列表的五根木棍中任选四根,它们将构成边长为 $5$ 的正方形,这仍然是一个边长为 $(5, 5)$ 的矩形。
**Definitions**
Let $ T \in \mathbb{Z}^+ $ be the number of test cases.
For each test case $ i \in \{1, \dots, T\} $:
- Let $ n_i \in \mathbb{Z} $, $ 4 \leq n_i \leq 10^6 $, denote the number of sticks.
- Let $ A_i = (a_{i,1}, a_{i,2}, \dots, a_{i,n_i}) $, where $ a_{i,j} \in \mathbb{Z}^+ $, $ 1 \leq a_{i,j} \leq 10^4 $, be the multiset of stick lengths.
**Constraints**
1. $ T \geq 1 $
2. For each test case $ i $, it is guaranteed that at least one rectangle can be formed from four distinct sticks in $ A_i $.
3. The total number of sticks across all test cases satisfies $ \sum_{i=1}^T n_i \leq 10^6 $.
**Objective**
For each test case $ i $, select four sticks $ (x, x, y, y) $ with $ x, y \in A_i $, $ x \leq y $, such that:
- $ x $ appears at least twice in $ A_i $,
- $ y $ appears at least twice in $ A_i $,
- The rectangle formed has side lengths $ x $ and $ y $.
Define:
- Perimeter: $ P = 2(x + y) $,
- Area: $ S = x \cdot y $,
- Objective function: $ R = \frac{P^2}{S} = \frac{4(x + y)^2}{xy} $.
Minimize $ R $ over all valid pairs $ (x, y) $ with $ x \leq y $.
If multiple pairs achieve the minimum $ R $, output any corresponding quadruple $ (x, x, y, y) $.
**Output**
For each test case $ i $, output the four selected stick lengths $ x, x, y, y $ in any order.
API Response (JSON)
{
"problem": {
"name": "C. Minimum Value Rectangle",
"description": {
"content": "You have $n$ sticks of the given lengths. Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be ",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF1027C"
},
"statements": [
{
"statement_type": "Markdown",
"content": "You have $n$ sticks of the given lengths.\n\nYour task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be ...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "你有 $n$ 根长度给定的木棍。\n\n你的任务是从中恰好选出四根,使得它们能构成一个矩形。不允许将任何木棍切割,矩形的每条边必须由一根完整的木棍构成,且每根木棍只能被选择一次。题目保证总能选出这样的四根木棍。\n\n设 $S$ 为矩形的面积,$P$ 为矩形的周长。\n\n所选矩形应使值 $\\frac{P^2}{S}$ 尽可能小。该值不进行任何四舍五入。\n\n如果有多个答案,输出任意一个即可。\n\n每个测试用例包...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ T \\in \\mathbb{Z}^+ $ be the number of test cases. \nFor each test case $ i \\in \\{1, \\dots, T\\} $: \n- Let $ n_i \\in \\mathbb{Z} $, $ 4 \\leq n_i \\leq 10^6 $, denote the number of...",
"is_translate": false,
"language": "Formal"
}
]
}