P16886 [GKS 2022 #E] Students and Mentors
Description
A group of $N$ students prepares together for upcoming programming competitions such as Kick Start and Code Jam by Google. To help each other prepare, it was decided that each student will pick a mentor among other students. A mentor will help their mentee to solve problems, learn algorithms, track their progress, and will generally support them throughout preparation.
Each student will have exactly one mentor among all other students, and a person can be a mentor to multiple people. For every student $i$ we know their rating $R_i$ which approximates how good that student is at programming competitions. Because it is believed that a mentor should not be much stronger than their mentee, a student $j$ can be a mentor of student $i$ only if $R_j \le 2 \times R_i$. Note that a mentor can even have a rating that is lower or equal to their mentee's rating.
Unsurprisingly, each student wants to have the strongest possible mentor. For each student, can you help to figure out what is the highest possible rating of a mentor they can pick?
Input Format
The first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each test case consists of $2$ lines.
The first line of each test case contains an integer $N$, representing the number of students in a group.
The second line of each test case contains $N$ integers $R_1$ $R_2$ $R_3$ $\ldots$ $R_N$ where $R_i$ is a rating of the $i$-th student.
Output Format
For each test case, output one line containing Case #$x$: $M_1$ $M_2$ $M_3$ $\ldots$ $M_N$ where $x$ is the test case number starting from $1$, and $M_i$ is the maximum possible rating of the $i$-th student's mentor or $-1$ if there are no suitable mentors for that student.
Explanation/Hint
In the Sample Case #$1$, there are $3$ students with ratings $2000$, $1500$, and $1900$. All students can pick any other student as their mentor, so they all pick a mentor with the highest possible rating. As a result, they pick mentors with ratings $1900$, $2000$, and $2000$, respectively. Note that in this case a student with the rating $2000$ will be a mentor of $2$ other students.
In the Sample Case #$2$, there are $5$ students with ratings $1000$, $600$, $1000$, $2300$, and $1800$ (note that some students may have equal ratings). For both students with ratings $1000$, the highest rated possible mentor for them has rating $1800$. They cannot pick a mentor with rating $2300$ as $2300 > 2 \times 1000$. Student with rating $600$ cannot pick mentors with ratings $1800$ or $2300$, so they pick a mentor with rating $1000$ (either of $2$ students with rating $1000$ works). Student with rating $2300$ can pick any other student as their mentor, so they pick a mentor with rating $1800$ — the highest possible. Finally, student with rating $1800$ can pick any other student as their mentor too, so they pick a mentor with the highest possible rating of $2300$. So in the end, the students pick the mentors with the ratings $1800$, $1000$, $1800$, $1800$, and $2300$, respectively.
In the Sample Case #$3$, there are $2$ students with ratings $2500$ and $1200$. For a student with rating $2500$, another student with rating $1200$ can be a mentor, and there are no other options. For a student with rating $1200$, we cannot assign a mentor with rating $2500$, as $2500 > 2 \times 1200$, and therefore this student has no suitable mentor. In the end, we output $1200$ and $-1$ as a result for this test case.
### Limits
$1 \le T \le 100$.
$1 \le R_i \le 10^6$, for all $i$.
**Test Set 1**
$2 \le N \le 1000$.
**Test Set 2**
$2 \le N \le 10^5$.