 # Given 2D array *ARRAY_1*

Given a 2D Array, :

1 1 1 0 0 0

0 1 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 0 0

A ‘T’ is a subset of values with indices falling in this pattern in array’s graphical representation:

A B C

D

E

There are 16 Ts in array. A T sum is the sum of a T’s value. Calculate T sum for every T in array, then print the maximum T sum. The array will always be 6*6.

Example:
Array=

-9 -9 -9 1 1 1
0 -9 0 4 3 2
-9 -9 -9 1 2 3
0 0 8 6 6 0
0 0 0 -2 0 0
0 0 1 2 4 0

The 16 Ts sum are:
-45 -26 -2 8
-18 -6 14 17
-27 -9 -2 12
8 15 20 16
The highest T sum is 20:
8 6 6
-2
2

Input Fromat:
Each of the 6 lines of inputs array[i] contains 6 space separated integers array[i][j].

Output Format:
Print the maximum T sum found in array

Constraints:
1) -9 <= array[i][j] <= 9
2) 0 <= i, j <= 5

Sample Input:
1 1 1 0 0 0

0 1 0 0 0 0

1 1 1 0 0 0

0 0 2 4 4 0

0 0 0 2 0 0

0 0 1 2 4 0

Sample Output:

14

Explanation:

Array contains the following Ts

1 1 1    1 1 0     1 0 0     0 0 0

1           0          0           0

1           1           0           0

0 1 0     1 0 0     0 0 0    0 0 0

1           1           0           0

0           2          4           4

1 1 1      1 1 0    1 0 0     0 0 0

0           2           4           4

0           0           2           0

0 0 2       0 2 4     2 4 4    4 4 0

0               0           2           0

0               1           2           4

The T with Maximum sum is

2 4 4

2

2

SOLUTION

``````#include <iostream

using namespace std;

int main()

{

int i,j;

int array;

int maxsum=0;

for(i=0;i<6;i++)

{

for(j=0;j<6;j++)

{

cin>>array[i][j];

}

}

for (i=1;i<5;i++)

{

int sum=0;

for(j=1;j<5;j++)

{

sum = array[i-1][j-1] + array[i-1][j] + array[i-1][j+1] + array[i][j] + array[i+1][j];

if(sum>maxsum)

{

maxsum=sum;

}

}

}

cout<<maxsum;

}
``````