#K56142. Quarterly Top Performer

    ID: 30133 Type: Default 1000ms 256MiB

Quarterly Top Performer

Quarterly Top Performer

You are given sales records from various employees for different quarters. Each record consists of an employee's name, the quarter (an integer from 1 to 4), and the sales amount made in that quarter. Your task is to determine the top performing employee for each quarter based on the highest sales. If two or more employees have the same sales, choose the one whose record appears first.

More formally, if we denote a record by a tuple \( (\text{name}, \text{quarter}, \text{sales}) \), then for each quarter \( q \) (\( q = 1,2,3,4 \)) you are required to find the employee \( E \) such that \( \text{sales} \) is maximized among the records where \( \text{quarter} = q \). In case of a tie, the employee whose record appears earlier in the input should be chosen.

inputFormat

The input is given via standard input (stdin). The first line contains a single integer \( n \) representing the number of sales records. Each of the next \( n \) lines contains a record in the format:

name quarter sales

Where:

  • name is a string representing an employee's name.
  • quarter is an integer (1 \( \leq q \leq \) 4).
  • sales is a non-negative integer representing the sales amount.

outputFormat

The output should be printed to standard output (stdout) as four lines. Each line corresponds to one quarter (from 1 to 4 in increasing order) and contains two values separated by a space: the quarter number and the top-performing employee's name for that quarter.

For example:

1 Bob
2 Alice
3 Cathy
4 Bob
## sample
8
Alice 1 150
Bob 1 200
Alice 2 300
Bob 2 250
Cathy 3 400
Alice 3 350
Bob 4 450
Cathy 4 450
1 Bob

2 Alice 3 Cathy 4 Bob

</p>