#K63392. Finding the Oldest User

    ID: 31743 Type: Default 1000ms 256MiB

Finding the Oldest User

Finding the Oldest User

You are given a list of users. Each user has a name (a string) and an age (an integer). Your task is to determine the name of the oldest user. In the case where there are multiple users with the maximum age, you should return the user whose name is lexicographically smallest.

If the list is empty, output None.

The selection criteria can be formulated as follows using LaTeX:

\( \text{Choose } u \text{ such that } u.age = \max_{v \in U} \{v.age\} \quad \text{and if } u_1.age = u_2.age, \text{ then } u_1.name \leq u_2.name \).

inputFormat

The input is read from stdin and follows the format below:

n
name1 age1
name2 age2
... 
name_n age_n

Where:

  • n is an integer representing the number of users. (It can be 0)
  • Each subsequent line contains a user's name (string) and age (integer) separated by a space.
If n is 0, then no user information follows.

outputFormat

Output a single line to stdout containing the name of the oldest user. In the case where there are multiple users with the same maximum age, output the lexicographically smallest name. If no users are provided (n = 0), output None.## sample

0
None