[Solution] Students and Mentors Round E Solution 2022 - Kick Start 2022
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, 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 we know their rating 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 can be a mentor of student only if . 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
The first line of the input gives the number of test cases, . test cases follow. Each test case consists of two lines.
The first line of each test case contains an integer , representing the number of students in a group.
The second line of each test case contains integers where is a rating of the -th student.
Output
For each test case, output one line containing Case #:
where is the test case number (starting from 1), and is the maximum possible rating of the -th student's mentor or if
there are no suitable mentors for that student.
Limits
Memory limit: 1 GB.
.
, for all .
Test Set 1
Time limit: 20 seconds.
.
Test Set 2
Time limit: 40 seconds.
.
In the Sample Case #1, there are three students with ratings , , and . 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 , , and , respectively. Note that in this case a student with the rating will be a mentor of two other students.
In the Sample Case #2, there are five students with ratings , , , , and (note that some students may have equal ratings). For both students with ratings , the highest rated possible mentor for them has rating . They cannot pick a mentor with rating as . Student with rating cannot pick mentors with ratings or , so they pick a mentor with rating (either of two students with rating works). Student with rating can pick any other student as their mentor, so they pick a mentor with rating — the highest possible. Finally, student with rating can pick any other student as their mentor too, so they pick a mentor with the highest possible rating of . So in the end, the students pick the mentors with the ratings , , , , and , respectively.
In the Sample Case #3, there are two students with ratings and . For a student with rating , another student with rating can be a mentor, and there are no other options. For a student with rating , we cannot assign a mentor with rating , as , and therefore this student has no suitable mentor. In the end, we output and as a result for this test case.
No comments:
Post a Comment