#K69277. Sum of Submatrix
Sum of Submatrix
Sum of Submatrix
You are given a two-dimensional matrix M of integers with dimensions m \times n and four integers row1, col1, row2, and col2 which specify the top-left and bottom-right corners of a submatrix. Your task is to calculate the sum of all the elements within this submatrix.
The submatrix sum can be formally defined as:
[ S = \sum_{i=row1}^{row2} \sum_{j=col1}^{col2} M_{ij} ]
Example:
Input: 3 3 1 2 3 4 5 6 7 8 9 0 0 2 2</p>Output: 45
inputFormat
The first line contains two space-separated integers m and n representing the dimensions of the matrix.
The next m lines each contain n space-separated integers representing the rows of the matrix.
The last line contains four space-separated integers: row1, col1, row2, and col2 which define the submatrix boundaries (inclusive, 0-indexed).
outputFormat
Output a single integer which is the sum of the elements in the specified submatrix.
## sample3 3
1 2 3
4 5 6
7 8 9
0 0 2 2
45