Table
Time limit1sMemory limit128 MB
Given an N by M table, compute each column's product and output the column index (largest index on tie) with the maximum product, handling big products across up to 1000 rows.
- Level
Medium4 of 10
- Topics
- Math, Simulation, Array
- Solved
- No attempts yet
Problem
A table with rows and columns stores 32-bit signed integers. The leftmost column is numbered 1, and the column numbers increase by 1 toward the right.
For each column (), let be the product of all the numbers in that column. Write a program that finds the number of the column with the largest value. If several columns share the largest value, print the one with the largest column number.
Input
The first line contains the number of test cases .
The first line of each test case contains the number of columns and the number of rows (, ). Each of the following lines contains 32-bit signed integers.
Output
For each test case, print on its own line the number of the column with the largest product.