#C12923. Dictionary with Maximum Value

    ID: 42404 Type: Default 1000ms 256MiB

Dictionary with Maximum Value

Dictionary with Maximum Value

Given a key and a list of dictionaries in JSON format, your task is to find and output the dictionary which has the highest integer value for the specified key. In case multiple dictionaries share the maximum value, return the one that appears first in the input. If the list is empty, output an empty dictionary {}.

The problem can be formulated as follows:

Let \( D = \{ d_1, d_2, \dots, d_n \} \) be a list of dictionaries and a string key be given. Find the dictionary \( d_{max} \) such that \[ d_{max} = \text{argmax}_{d \in D} \; d[key] \] (Note that in case of a tie, the first occurrence is chosen.)

inputFormat

The input is given via standard input and has the following format:

  1. The first line contains a string representing the key.
  2. The second line contains an integer \( n \) representing the number of dictionaries.
  3. The next \( n \) lines each contain a dictionary in JSON format.

For example:

score
3
{"name": "Alice", "age": 30, "score": 95}
{"name": "Bob", "age": 25, "score": 91}
{"name": "Charlie", "age": 35, "score": 95}

outputFormat

The output is a single line printed to standard output. It should be the JSON representation of the dictionary which has the maximum value for the provided key. If the list is empty, output {}.

## sample
score
1
{"name": "Alice", "age": 30, "score": 95}
{"name": "Alice", "age": 30, "score": 95}