Find the perfect land of C shape
Debasis is searching for a perfect land to build a new house. There is an area of size N*M and each point of N*M has a value. But he wants exactly a land of size 3*3 but the land should be perfect.
A perfect land is a land whose 'C' shape value is maximum.
You being his friend, help him to find the perfect land.
Input
First line of the input is two space separated integer N and M
Second line of the input contains the matrix of size N*M (N rows M columns).
Output
A single integer containing the sum of the perfect land.
Example:
Input:
6 6
0 0 1 1 1 0
0 0 1 0 0 0
0 0 1 1 1 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Output:
7
Here is the perfect land whose sum value is maximum.
Note: Before going to solution please try it by yourself.
C++ implementation:
Output

need an explanation for this answer? contact us directly to get an explanation for this answer