An automated greenhouse arranges its garden beds as an m x n grid of soil-moisture sensors. Each row of the grid is one bed; each entry in that row is a single sensor reading, either 0 (soil moisture is fine) or 1 (the sensor is flagging dryness). The greenhouse controller must decide which single bed the irrigation crew should visit first: the bed with the greatest number of flagged sensors. If two or more beds tie for the highest flagged-sensor count, the controller always prefers the bed that appears earliest in the grid (rows are 0-indexed from the top).
Line 1: two integers m and n -- the number of beds (rows) and the number of sensors per bed (columns).
Each of the next m lines contains n integers, each 0 or 1, separated by spaces -- the sensor readings for that bed.
Print two integers separated by a space: the 0-based index of the bed with the most flagged sensors (ties broken by the smallest index), followed by the number of flagged sensors in that bed.
1 <= m <= 10001 <= n <= 1000Example 1
Input
2 4 0 0 0 1 1 0 1 1
Expected
1 3
Explanation
Bed 0 has readings [0,0,0,1] with 1 flagged sensor. Bed 1 has readings [1,0,1,1] with 3 flagged sensors. Bed 1 has strictly more flagged sensors, so the answer is "1 3".
Example 2
Input
3 2 0 0 1 0 0 1
Expected
1 1
Explanation
Bed 0 has 0 flagged sensors, bed 1 has 1 flagged sensor, and bed 2 also has 1 flagged sensor. Beds 1 and 2 tie for the maximum, and ties are broken by the smallest index, so the answer is "1 1".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →