找最大值干嘛呀。。
表面积只要上下左右前后扫描6次就好了,上下是固定的就不用扫描了,
每个竖条方块记录一下比上下左右高的部分就好了
tmp =[int(x) for x in input().split()]
M,N = tmp[0],tmp[1]
data = []
data.append([0 for _ in range(N+2)])
for i in range(M):
tmp = []
tmp.append(0)
tmp.extend([int(x) for x in input().split()])
tmp.append(0)
data.append(tmp)
data.append([0 for i in range(N+2)])
base = M*N*2
for i in range(1,M+1):
for j in range(1,N+1):
long = 0
long += max(0,data[i][j]-data[i-1][j])
long += max(0,data[i][j]-data[i+1][j])
long += max(0,data[i][j]-data[i][j-1])
long += max(0,data[i][j]-data[i][j+1])
base+=long
print(base)