A space-flight academy runs trainees through repeated cockpit simulations in small groups called pods. Every simulation run a trainee completes is logged as one record: the trainee's pod, the trainee's id, and the score earned on that run. A trainee can appear in multiple records (one per simulation run they completed), but every record naming a given trainee id always names the same pod for that id.
For every trainee, define their total score as the sum of the scores across all of their logged runs. For every pod, define its spread as the difference between the largest total score among its trainees and the smallest total score among its trainees (a pod with only one trainee has spread 0).
Report the pod with the largest spread. If two or more pods are tied for the largest spread, report the one whose name is lexicographically smallest.
A single line with the chosen pod's name, a space, and its spread (an integer).
Example 1
Input
5 ALPHA 1 50 ALPHA 2 80 BETA 3 60 BETA 4 65 ALPHA 1 20
Expected
ALPHA 10
Explanation
Trainee 1 has two runs in ALPHA (50 and 20), so their total is 70. Trainee 2's total is 80. Pod ALPHA's trainee totals are {70, 80}, giving spread 80 - 70 = 10. Trainee 3 (BETA) totals 60 and trainee 4 (BETA) totals 65, giving BETA spread 65 - 60 = 5. ALPHA's spread of 10 is larger, so the answer is "ALPHA 10".
Example 2
Input
3 BLUE 10 40 RED 11 90 RED 12 30
Expected
RED 60
Explanation
BLUE has a single trainee (id 10) with total 40, so BLUE's spread is 0. RED has two trainees with totals 90 and 30, so RED's spread is 90 - 30 = 60. RED's spread is larger, so the answer is "RED 60".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →