#K52767. The Fastest Relay Team Problem

    ID: 29383 Type: Default 1000ms 256MiB

The Fastest Relay Team Problem

The Fastest Relay Team Problem

You are given a relay race where each team must complete m segments. Each segment j has a distance dj (in meters) and each team member has a speed. The time taken by a team to complete the race is computed using the formula:

\( T = \sum_{j=1}^{m} \frac{d_j}{s_j} \)

where \(s_j\) is the speed of the runner for segment j. Given multiple test cases, your task is to determine the 1-based index of the team which finishes the race in the shortest total time for each test case.

The input is read from standard input and the output should be written to standard output.

inputFormat

The first line contains an integer T, the number of test cases. For each test case:

  • The first line contains two integers n and m, representing the number of teams and the number of segments, respectively.
  • The second line contains m integers: the distances of the segments.
  • Then follow n lines, each containing m integers representing the speeds (in units per second) for the corresponding team.

Input is given via stdin.

outputFormat

For each test case, output a single line containing the 1-based index of the team with the shortest total running time.

Output is to be written to stdout.

## sample
1
3 2
100 200
10 5
8 4
12 6
3

</p>