#K75997. Weakest Row or Column Strength
Weakest Row or Column Strength
Weakest Row or Column Strength
You are given a 2D grid (matrix) of integers where each value represents the strength of an individual in a team formation. Your task is to determine the weakest line of defense by computing the sum of each row and each column, and then returning the minimum sum among them.
Formally, given a matrix \(A\) of size \(N \times M\), compute the row sums \(R_i = \sum_{j=1}^{M} A_{i,j}\) for \(1 \leq i \leq N\) and column sums \(C_j = \sum_{i=1}^{N} A_{i,j}\) for \(1 \leq j \leq M\). The answer is \(min(\min_{1\le i\le N} R_i, \min_{1\le j\le M} C_j)\).
Input is provided via standard input (stdin) and the result must be printed to standard output (stdout).
inputFormat
The first line contains two integers, \(N\) and \(M\), which denote the number of rows and columns in the grid, respectively. This is followed by \(N\) lines each containing \(M\) space-separated integers representing the elements of the grid.
outputFormat
Output a single integer which is the minimum sum computed from either any row or any column of the grid.
## sample3 4
10 20 30 40
5 10 15 20
25 40 55 70
40
</p>