Problem p03240 (python)

Fixed submission:
import numpy as np
N = int(input())

xyh = []
for _ in range(N):
    xyh.append(list(map(int, input().split())))
xyh = np.array(xyh)
xyh = xyh[np.argsort(xyh[:, 2])[::-1]]

cxylist = [[i, j] for i in range(101) for j in range(101)]

Hdict = [[] for i in range(101)]
for i in range(len(cxylist)):
    x, y, h =xyh[0]
    H = h + abs(x-cxylist[i][0]) + abs(y-cxylist[i][1])
    Hdict[cxylist[i][0]].append(H)

def calh(cxylist, x, y, h):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        H = h + abs(x-cx) + abs(y-cy)
        if Hdict[cx][cy] == H:
            newcxylist.append([cx, cy])
    return newcxylist

def checkh(cxylist, x, y):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        if Hdict[cx][cy] - abs(x-cx) - abs(y-cy) <= 0:
            newcxylist.append([cx, cy])
    return newcxylist

for n in range(N-1):
    if xyh[n+1][2] != 0:
        cxylist = calh(cxylist, xyh[n+1][0], xyh[n+1][1], xyh[n+1][2])
    else:
        cxylist = checkh(cxylist, xyh[n+1][0], xyh[n+1][1])

print(cxylist[0][0], cxylist[0][1], Hdict[cxylist[0][0]][cxylist[0][1]])

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())

xyh = []
for _ in range(N):
    xyh.append(list(map(int, input().split())))
xyh = np.array(xyh)
xyh = xyh[np.argsort(xyh[:, 2])[::-1]]

cxylist = [[i, j] for i in range(101) for j in range(101)]

Hdict = [[] for i in range(101)]
for i in range(len(cxylist)):
    x, y, h =xyh[0]
    H = h + abs(x-cxylist[i][0]) + abs(y-cxylist[i][1])
    Hdict[cxylist[i][0]].append(H)

def calh(cxylist, x, y, h):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        H = h + abs(x-cx) + abs(y-cy)
        if Hdict[cx][cy] == H:
            newcxylist.append([cx, cy])
    return newcxylist

def checkh(cxylist, x, y):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        if Hdict[cx][cy] - abs(x-cx) - abs(y-cy) <= 0:
            newcxylist.append([cx, cy])
    return newcxylist

for n in range(N-1):
    if xyh[n][2] != 0:
        cxylist = calh(cxylist, xyh[n+1][0], xyh[n+1][1], xyh[n+1][2])
    else:
        cxylist = checkh(cxylist, xyh[n+1][0], xyh[n+1][1])

print(cxylist[0][0], cxylist[0][1], Hdict[cxylist[0][0]][cxylist[0][1]])

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())

xyh = []
for _ in range(N):
    xyh.append(list(map(int, input().split())))
xyh = np.array(xyh)
xyh = xyh[np.argsort(xyh[:, 2])[::-1]]

cxylist = [[i, j] for i in range(101) for j in range(101)]

Hdict = [[] for i in range(101)]
for i in range(len(cxylist)):
    x, y, h =xyh[0]
    H = h + abs(x-cxylist[i][0]) + abs(y-cxylist[i][1])
    Hdict[cxylist[i][0]].append(H)

def calh(cxylist, x, y, h):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        H = h + abs(x-cx) + abs(y-cy)
        if Hdict[cx][cy] == H:
            newcxylist.append([cx, cy])
    return newcxylist

def checkh(cxylist, x, y):
    newcxylist = []
    for i in range(len(cxylist)):
        cx, cy = cxylist[i]
        if Hdict[cx][cy] - abs(x-cx) - abs(y-cy) <= 0:
            newcxylist.append(cx)
    return newcxylist

for n in range(N-1):
    if xyh[n][2] != 0:
        cxylist = calh(cxylist, xyh[n+1][0], xyh[n+1][1], xyh[n+1][2])
    else:
        cxylist = checkh(cxylist, xyh[n+1][0], xyh[n+1][1])

print(cxylist[0][0], cxylist[0][1], Hdict[cxylist[0][0]][cxylist[0][1]])