#K59047. Analyzing User Viewing Patterns

    ID: 30777 Type: Default 1000ms 256MiB

Analyzing User Viewing Patterns

Analyzing User Viewing Patterns

You are given multiple datasets representing user viewing records. Each dataset starts with two integers m and n, representing the number of viewers and the number of viewing sessions per viewer, respectively. The following m lines each contain a viewer id followed by n pairs: a session id and the viewing time in seconds. Your task is to determine, for each dataset, the viewer who watched the most unique sessions and the viewer who accumulated the longest total viewing time. In the case of a tie, choose the viewer who appears first in the input order.

The input contains multiple datasets separated by a blank line, and ends with a line containing 0 0, which should not be processed.

inputFormat

The input is read from standard input (stdin) and contains multiple datasets. Each dataset is structured as follows:

  • The first line contains two integers m and n.
  • The next m lines each start with a viewer id, followed by n pairs where each pair consists of a session id and a viewing time (in seconds).
  • Datasets are separated by a blank line. The input ends with a line containing 0 0.

outputFormat

For each dataset, output two lines to standard output (stdout):

  1. The viewer id with the highest number of unique sessions watched.
  2. The viewer id with the longest total viewing time.

There should be no extra characters or spaces in the output.

## sample
3 4
1 101 1000 102 1500 103 2000 104 2500
2 102 2000 103 1500 101 2500 104 3000
3 101 3000 102 4000 103 5000 104 6000

2 3
4 201 5000 202 6000 203 7000
5 202 7000 203 6000 201 5000

0 0
1

3 4 4

</p>