#K6326. Maximum Subgrid Sum

    ID: 31714 Type: Default 1000ms 256MiB

Maximum Subgrid Sum

Maximum Subgrid Sum

You are given an n x n grid with integer values and a number k. Your task is to find the maximum sum of a contiguous subgrid of size k x k.

More formally, for a given grid G, you need to compute:

$$\max_{1 \le i \le n-k+1 \; ,\; 1 \le j \le n-k+1} \sum_{p=0}^{k-1}\sum_{q=0}^{k-1} G_{i+p,j+q}$$

The input is read from stdin and the result should be printed to stdout.

inputFormat

The first line of input contains two integers n and k where:

  • n is the size of the grid (the grid is n x n).
  • k is the size of the subgrid to be considered (k x k).

Each of the next n lines contains n space-separated integers representing the grid rows.

outputFormat

Output a single integer which is the maximum sum of any k x k subgrid of the given grid. The output should be printed to stdout.

## sample
4 2
1 3 5 2
7 1 8 6
3 4 2 0
8 7 6 5
22

</p>