Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3.7
- # -*- coding: utf-8 -*import
- rows, columns = map(int, input().split())
- matrix = [[int(x) for x in input().split()] for _ in range(rows)]
- row = 0
- col = 0
- rows_count = rows - 3
- columns_count = columns - 3
- def find_squares(r: int, c: int, r_c: int, c_c: int):
- s = []
- while True:
- if r == r_c and c > c_c:
- break
- if c > c_c:
- r += 1
- c = 0
- j = 0
- k = 0
- sq = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
- for i in range(r, r + 3):
- for y in range(c, c + 3):
- sq[j][k] = matrix[i][y]
- k += 1
- j += 1
- k = 0
- s.append(sq)
- c += 1
- return s
- squares = find_squares(row, col, rows_count, columns_count)
- sums = [sum(sum(x) for x in y) for y in squares]
- max_ones = [x for x in sums if x == max(sums)]
- winner = squares[sums.index(max_ones[0])]
- print(f'Sum = {max_ones[0]}')
- print('\n'.join([' '.join([str(y) for y in x]) for x in winner]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement