#K78682. Maximum Hourglass Sum
Maximum Hourglass Sum
Maximum Hourglass Sum
Given an MxN matrix of integers, an hourglass shape is defined as follows:
[
a\quad b\quad c
]
[\quad d]
[
e\quad f\quad g
]
Your task is to compute the maximum hourglass sum in the matrix. An hourglass sum is defined as the sum of the 7 values in an hourglass shape. It is guaranteed that the matrix dimensions are such that at least one hourglass exists.
inputFormat
The first line contains two integers M and N, separated by a space, representing the number of rows and columns of the matrix respectively. The next M lines each contain N space-separated integers representing the matrix elements.
outputFormat
Output a single integer – the maximum hourglass sum found in the matrix.## sample
3 3
1 1 1
0 1 0
1 1 1
7