#K84502. Highest Scoring Employee By Department

    ID: 36433 Type: Default 1000ms 256MiB

Highest Scoring Employee By Department

Highest Scoring Employee By Department

You are given a list of employee records. Each record contains an employee's name, department, and score separated by whitespace. For each department, your task is to determine the employee with the highest score. In the event of a tie (i.e. multiple employees have the same highest score), select the employee with the lexicographically smallest name.

The output should list the result for each department in ascending order of department names. Each output line must contain the department, the chosen employee's name, and their score, separated by a single space.

Note: If there are multiple employees with the same highest score, the tie is broken by choosing the one whose name is smallest in lexicographical order.

Mathematical formulation:
For each department \( D \), let \( S(D) \) be the set of employees in department \( D \). For an employee \( e \) with score \( score(e) \) and name \( name(e) \), we want to find \[ \text{argmax}_{e \in S(D)}\; \Bigl( score(e), -\text{lex}(name(e)) \Bigr), \] where \( -\text{lex}(name(e)) \) indicates that in case of a tie on \( score(e) \), the employee with the lexicographically smallest name is selected.

inputFormat

The first line of the input contains a single integer \( n \) which represents the number of employee records. The following \( n \) lines each contain an employee record in the format:

Name Department Score

Each field is separated by a single space.

outputFormat

For each department, output one line containing the department name, the employee's name, and the employee's score of the highest scoring employee in that department. The departments must be sorted in lexicographical order. If two or more employees tie for the highest score in a department, choose the one with the lexicographically smallest name.

## sample
5
Alice HR 90
Bob IT 85
Charlie IT 85
Dave HR 95
Eve HR 95
HR Dave 95

IT Bob 85

</p>