Some crazy guy shows you a n x n grid of integers.
He then asks you to find the maximum value of the sum of all integers inside any k x k northwest oriented right angled triangle in the grid.
The k x k triangle must reside FULLY in the grid.
Being a smart programmer, you decide to use a computer to solve the madman's question.
The first line of input will consist of 2 integers n (1 ≤ n ≤ 5,000) and k (1 ≤ k ≤ n).
The following n lines will contain n integers each. Each integer a will satisfy 1 ≤ a ≤ 400.
For 20% of the test cases, n ≤ 50.
For 50% of the cases (including the above 20%), n ≤ 300.
5 3 1 2 3 1 3 3 1 1 1 4 1 2 3 1 5 5 5 5 5 5 5 5 3 5 5
22
3 1 5 5 5 3
which gives 22.
Notice that the incomplete triangle bit which gives a better sum of 23:
5 5 5 3 5
is not allowed.
Subtask | Score |
---|---|
1 | 20 |
2 | 30 |
3 | 50 |
4 | 0 |