#C4880. Submatrix Sum

    ID: 48467 Type: Default 1000ms 256MiB

Submatrix Sum

Submatrix Sum

Given a matrix of integers and two coordinate pairs representing the top-left and bottom-right corners of a submatrix, compute the sum of all elements within that submatrix. The matrix is 0-indexed. Mathematically, if the submatrix is defined by the coordinates \((t, l)\) and \((b, r)\), then the answer is given by:

\[\text{Sum} = \sum_{i=t}^{b} \sum_{j=l}^{r} matrix[i][j]\]

Your task is to read the input from standard input, compute the submatrix sum, and output the result to standard output.

inputFormat

The input is given via standard input in 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 of the matrix.
  • The next n lines each contain m integers separated by spaces, representing the rows of the matrix.
  • The following line contains two integers representing the row and column of the top-left corner of the submatrix.
  • The last line contains two integers representing the row and column of the bottom-right corner of the submatrix.

outputFormat

Output a single integer, the sum of all the elements within the specified submatrix.

## sample
3 3
1 2 3
4 5 6
7 8 9
1 1
2 2
28