#C2068. Sum of Submatrix Elements
Sum of Submatrix Elements
Sum of Submatrix Elements
You are given an integer matrix of size \(N \times M\) and four indices \(l_1\), \(r_1\), \(l_2\), \(r_2\) which denote the top-left and bottom-right corners of a submatrix. Your task is to compute the sum of all elements present in the specified submatrix.
You can assume that the indices satisfy the conditions \(0 \le l_1 \le l_2 < N\) and \(0 \le r_1 \le r_2 < M\).
Example:
Input: 3 3 1 2 3 4 5 6 7 8 9 1 1 2 2</p>Output: 28
In the above example, the submatrix chosen is:
5 6 8 9
whose sum is (28).
inputFormat
The first line contains two integers (N) and (M), representing the number of rows and columns of the matrix. Each of the next (N) lines contains (M) space-separated integers corresponding to the matrix row. The last line contains four integers (l_1), (r_1), (l_2), (r_2) denoting the 0-based coordinates of the top-left and bottom-right corners of the submatrix.
outputFormat
Output a single integer which is the sum of all the elements in the specified submatrix.## sample
3 3
1 2 3
4 5 6
7 8 9
1 1 2 2
28