Students and Mentors
InterviewMemory limit1024 MB
For each student, find the highest rating among other students that is at most twice their own rating, or -1 if no such student exists.
- Level
Easy3 of 10
- Topics
- Sorting, Binary search
- Solved
- No attempts yet
Problem
A group of students prepares together for upcoming programming competitions such as Kick Start and Code Jam by Google. To help each other prepare, each student picks a mentor among the other students. A mentor helps their mentee solve problems, learn algorithms, track progress, and support them throughout preparation.
Each student has exactly one mentor among all other students, and one person can be a mentor to several students. Each student has a rating that approximates how strong they are at programming competitions. A mentor should not be much stronger than their mentee, so student can be the mentor of student only if . A mentor may have a rating lower than or equal to their mentee's rating.
Each student wants the strongest possible mentor. For each student, find the highest rating of a mentor they can pick.
Input
The first line contains the number of test cases . Each of the test cases follows on two lines.
The first line of each test case contains the number of students .
The second line contains integers , separated by spaces. is the rating of the -th student.
Output
For each test case, print one line in the form Case #x: M1 M2 M3 ... MN. Here is the test case number starting from 1, and is the highest rating of a mentor the -th student can have. If the -th student has no suitable mentor, print for that student.
Limits
- .
- for all .