Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import sys
  2.  
  3. def main():
  4. m, n = map(int, sys.stdin.readline().split(' '))
  5. a = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(m)]
  6.  
  7. assert 1 <= min(m, n) and 6 <= max(n, m) <= 1000
  8. for r in a:
  9. assert 1 <= min(r) and max(r) <= 1000
  10.  
  11. b = [[0] * n for _ in range(m)]
  12.  
  13. for i in range(m):
  14. for j in range(n):
  15. for di in range(-1, 2):
  16. for dj in range(-1, 2):
  17. if 0 <= i + di < m and 0 <= j + dj < n:
  18. b[i][j] += a[i + di][j + dj]
  19. b[i][j] += a[i][j]
  20.  
  21. best = max(map(max, b))
  22.  
  23. answer = 0
  24.  
  25. for i in range(m):
  26. for j in range(n):
  27. if answer == best * 2:
  28. continue
  29. if b[i][j] == best:
  30. current = 0
  31. for ii in range(m):
  32. for jj in range(n):
  33. if abs(i - ii) > 2 or abs(j - jj) > 2:
  34. current = max(current, b[i][j] + b[ii][jj])
  35. answer = max(answer, current)
  36.  
  37. print('{}'.format(answer / 2))
  38.  
  39.  
  40. if __name__ == '__main__':
  41. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement