#C3769. Book Genre Categorization

    ID: 47232 Type: Default 1000ms 256MiB

Book Genre Categorization

Book Genre Categorization

You are given N books, each with a unique identifier and three scores corresponding to three genres: Fiction, Non-Fiction, and Science. Your task is to determine the genre for each book based on its highest score. In case of ties, use the following priority order:

  • Genre 1: Fiction (if the Fiction score is greater than or equal to both Non-Fiction and Science scores, i.e. \( f \ge nf \) and \( f \ge s \)).
  • Genre 2: Non-Fiction (if Fiction is not dominating and Non-Fiction score is greater than or equal to Science, i.e. \( nf \ge s \)).
  • Genre 3: Science (otherwise).

Formally, for a book with scores \( f \), \( nf \), and \( s \), the genre assignment is defined as:

\[ \text{genre} = \begin{cases} 1, & \text{if } f \ge nf \text{ and } f \ge s,\\ 2, & \text{if } f

inputFormat

The first line of input contains an integer N (the number of books). This is followed by N lines, each containing four space-separated integers:

  • id - the unique identifier for the book.
  • f_score - the score for the Fiction genre.
  • nf_score - the score for the Non-Fiction genre.
  • s_score - the score for the Science genre.

outputFormat

For each book, output a single line containing two space-separated integers: the book's id and the assigned genre number. The genres are numbered as follows:

  • 1: Fiction
  • 2: Non-Fiction
  • 3: Science

The order of the output lines should match the order of the input books.

## sample
1
1001 85 90 95
1001 3