#C6554. Find the Book with the Most Pages

    ID: 50327 Type: Default 1000ms 256MiB

Find the Book with the Most Pages

Find the Book with the Most Pages

You are given n books. Each book is identified by its ISBN (a string) and the number of pages it contains. Your task is to determine the ISBN of the book with the highest number of pages. If there are multiple books with the same maximum number of pages, output the one with the smallest ISBN when compared lexicographically.

Formally, let \(p_i\) denote the number of pages of the \(i\)-th book, and \(s_i\) its ISBN. You must find the ISBN \(s_k\) such that \(p_k = \max_{1 \leq i \leq n}\{p_i\}\). In the event of ties, choose the one for which \(s_k\) is minimum, i.e., \[ s_k = \min\{s_i \mid p_i = \max_{1 \leq j \leq n}\{p_j\}\}\]

inputFormat

The input is provided from stdin in the following format:

 n
 ISBN_1 pages_1
 ISBN_2 pages_2
 ...
 ISBN_n pages_n

Where:

  • n is the number of books.
  • Each subsequent line contains an ISBN (a string without spaces) and an integer representing the number of pages, separated by a space.

outputFormat

Output a single line to stdout containing the ISBN of the book that meets the criteria.

## sample
4
1234567890 200
0987654321 300
1111111111 300
2222222222 150
0987654321