#C5137. Maximum Sum Subgrid

    ID: 48753 Type: Default 1000ms 256MiB

Maximum Sum Subgrid

Maximum Sum Subgrid

You are given a grid of integers with N rows and M columns. Your task is to compute the maximum sum of any subgrid of size A x B from the given grid.

A subgrid is defined as a contiguous block within the grid. The subgrid of size A x B starts at some cell (i, j) where the block fully fits within the grid. The sum of a subgrid is the sum of its elements.

The formula for the sum S of a subgrid starting at row i and column j is given by:

$$S = \sum_{p=0}^{A-1} \sum_{q=0}^{B-1} grid_{i+p, j+q} $$

Your program should read the input from stdin and output the answer to stdout.

inputFormat

The first line contains four space-separated integers: N M A B, where:

  • N and M denote the number of rows and columns in the grid respectively,
  • A and B denote the number of rows and columns of the subgrid respectively.

Each of the next N lines contains M space-separated integers representing the grid.

outputFormat

Output a single integer which is the maximum sum of any subgrid of size A x B.

## sample
4 5 2 3
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
99