#C6891. Maximum Sum Subgrid
Maximum Sum Subgrid
Maximum Sum Subgrid
You are given a grid with n rows and m columns where each cell contains an integer representing the number of flowers available. Your task is to determine the maximum sum of flowers that can be collected from any rectangular subgrid of the given grid.
A subgrid is defined as any contiguous rectangular block within the grid. If the subgrid is defined by its top-left corner (i₁, j₁) and bottom-right corner (i₂, j₂), then its sum is given by:
$$S = \sum_{i=i_1}^{i_2} \sum_{j=j_1}^{j_2} A_{ij},$$where \(A_{ij}\) represents the number of flowers in the cell located at row \(i\) and column \(j\). Output the maximum sum found among all possible subgrids.
inputFormat
The input is read from stdin and has the following format:
- The first line contains two integers \(n\) and \(m\), where \(n\) is the number of rows and \(m\) is the number of columns in the grid.
- The next \(n\) lines each contain \(m\) integers separated by spaces, representing the values in the grid.
outputFormat
Output a single integer to stdout, which is the maximum sum of flowers in any subgrid of the given grid.
## sample3 3
1 2 3
4 5 6
7 8 9
45