Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rows, cols = [int(x) for x in input(" ").split()]
- matrix = []
- [matrix.append([int(x) for x in input().split(" ")]) for row in range(rows)]
- max_sum = None
- best_matrix = None
- for row in range(rows - 2):
- for col in range(cols - 2):
- first_row = matrix[row][col:col + 3]
- second_row = matrix[row + 1][col:col + 3]
- third_row = matrix[row + 2][col:col + 3]
- current_sum = sum(first_row) + sum(second_row) + sum(third_row)
- current_matrix = [first_row] + [second_row] + [third_row]
- if not max_sum:
- max_sum = current_sum
- best_matrix = current_matrix
- else:
- if current_sum > max_sum:
- max_sum = current_sum
- best_matrix = current_matrix
- print(f"Sum = {max_sum}")
- for i in range(len(best_matrix)):
- current_row = [str(x) for x in best_matrix[i]]
- print(" ".join(current_row))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement