-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2DArray.py
39 lines (25 loc) · 832 Bytes
/
2DArray.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
arr = []
for _ in range(6):
arr.append(list(map(int, input().rstrip().split())))
# calculate the maximum hourglass sum
# the sum can be negative, so the minimum hourglass sum = -9 * 7 = -63
maxSum = -63
for i in range(4):
for j in range(4):
# sum of top 3 elements
top = sum(arr[i][j:j+3])
# sum of the mid element
mid = arr[i+1][j+1]
# sum of bottom 3 elements
bottom = sum(arr[i+2][j:j+3])
hourglass = top + mid + bottom
if hourglass > maxSum:
maxSum = hourglass
print(maxSum)