#K69702. Submatrix Sum
Submatrix Sum
Submatrix Sum
Given an \(m \times n\) matrix of integers, your task is to compute the sum of a specified submatrix. The submatrix is defined by its top-left corner \((row1, col1)\) and its bottom-right corner \((row2, col2)\), where the indices are zero-based.
For example, consider the following matrix:
1 2 3 4 5 6 7 8 9
If you are given the query with \(row1 = 1, col1 = 1, row2 = 2, col2 = 2\), the corresponding submatrix is:
5 6 8 9
The sum is \(5 + 6 + 8 + 9 = 28\).
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains two integers (m) and (n), representing the number of rows and columns of the matrix respectively.
- The next (m) lines each contain (n) integers, representing the elements of the matrix.
- The final line contains four integers: (row1), (col1), (row2), and (col2), which define the top-left and bottom-right coordinates of the submatrix you need to sum.
outputFormat
Output a single integer, which is the sum of all the elements in the specified submatrix. The answer should be written to standard output (stdout).## sample
3 3
1 2 3
4 5 6
7 8 9
1 1 2 2
28