#C5870. Determine the Winner in a Coding Competition

    ID: 49567 Type: Default 1000ms 256MiB

Determine the Winner in a Coding Competition

Determine the Winner in a Coding Competition

In a coding competition, multiple participants compete over several rounds. Each participant earns a score in every round. The winner of each test case is determined based on the following criteria:

  1. The participant with the highest total score wins.
  2. If there is a tie in the total score, the participant with the higher score in the last round is declared the winner.

You are given multiple test cases. For each test case, you will be provided with the number of participants, the number of rounds, and the scores of each participant for every round. Your task is to determine the index (0-indexed) of the winning participant for each test case.

The scoring formula can be formally expressed in ( \LaTeX ) as follows:

[ \text{winner} = \arg\max_{i} \left(\sum_{j=1}^{R} s_{ij},; s_{iR}\right) ]

where ( s_{ij} ) is the score of participant ( i ) in round ( j ) and ( R ) is the total number of rounds.

Read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The input begins with an integer ( T ) representing the number of test cases. Each test case consists of:

  • A line containing two integers ( N ) and ( R ), where ( N ) is the number of participants and ( R ) is the number of rounds.
  • ( N ) subsequent lines each containing ( R ) space-separated integers representing the scores of a participant in each round.

For example:

2 3 3 10 20 30 15 25 35 20 25 30 2 4 5 10 15 20 10 20 30 40

outputFormat

For every test case, output a single line with an integer representing the 0-indexed winner's index for that test case.

For the sample input above, the correct output is:

1 1## sample

1
3 3
10 20 30
15 25 35
20 25 30
1