Problem p03240 (python)

Fixed submission:
#!/usr/bin/env python

N = int(input())

FIELD_SIZE = 101

x = []
y = []
h = []
for n in range(N):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    h.append(int(inputs[2]))

H = [[0] * FIELD_SIZE for n in range(FIELD_SIZE)]
determined_flag = False

for n in range(N):
    for cx in range(FIELD_SIZE):
        for cy in range(FIELD_SIZE):

            ch = h[n] + abs(x[n] - cx) + abs(y[n] - cy)
            if n == 0:
                H[cx][cy] = ch

            elif determined_flag:
                if h[n] != 0:
                    if ch == H[cx][cy]:
                        pass
                    else:
                        H[cx][cy] = 0
                else:
                    if ch >= H[cx][cy]:
                        pass
                    else:
                        H[cx][cy] = 0

            else:
                if h[n] != 0:
                    if ch <= H[cx][cy]:
                        H[cx][cy] = ch
                    else:
                        H[cx][cy] = 0
                else:
                    H[cx][cy] = min(H[cx][cy], ch)
    if h[n] != 0:
        determined_flag = True


for cx in range(FIELD_SIZE):
    for cy in range(FIELD_SIZE):
        if H[cx][cy] >= 1:
            print(cx, cy, H[cx][cy])

Buggy submission (verdict: Runtime Error):
N = int(input())

FIELD_SIZE = 101

x = []
y = []
h = []
for n in range(N):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    h.append(int(inputs[2]))

H = [[-1] * FIELD_SIZE for n in range(FIELD_SIZE)]
under_flag = True

for n in range(N):
    for cx in range(FIELD_SIZE):
        for cy in range(FIELD_SIZE):
            if h[n] != 0:
                under_flag = False

            ch = h[n] + abs(x[n] - cx) + abs(y[n] - cy)
            if H[cx][cy] == -1:
                H[cx][cy] = ch
            elif under_flag and ch <= H[cx][cy]:
                H[cx][cy] = ch
            elif h[n] != 0 and H[cx][cy] == ch:
                H[cx][cy] = ch
            elif h[n] == 0 and H[cx][cy] <= ch:
                pass
            else:
                H[cx][cy] = None

for cx in range(FIELD_SIZE):
    for cy in range(FIELD_SIZE):
        if H[cx][cy] is not None:
            print(cx, cy, H[cx][cy])

Buggy submission (verdict: Runtime Error):
N = int(input())

FIELD_SIZE = 101

x = []
y = []
h = []
for n in range(N):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    h.append(int(inputs[2]))

H = [[-1] * FIELD_SIZE for n in range(FIELD_SIZE)]
under_flag = True

for n in range(N):
    for cx in range(FIELD_SIZE):
        for cy in range(FIELD_SIZE):
            if h[n] != 0:
                under_flag = False

            ch = h[n] + abs(x[n] - cx) + abs(y[n] - cy)
            if H[cx][cy] == -1:
                H[cx][cy] = ch
            elif under_flag and ch <= H[cx][cy]:
                H[cx][cy] = ch
            elif H[cx][cy] == ch:
                H[cx][cy] = ch
            else:
                H[cx][cy] = None

for cx in range(FIELD_SIZE):
    for cy in range(FIELD_SIZE):
        if H[cx][cy] is not None:
            print(cx, cy, H[cx][cy])

Buggy submission (verdict: Runtime Error):
N = int(input())

FIELD_SIZE = 101

x = []
y = []
h = []
for n in range(N):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    h.append(int(inputs[2]))

H = [[-1] * FIELD_SIZE for n in range(FIELD_SIZE)]
under_flag = True

for n in range(N):
    for cx in range(FIELD_SIZE):
        for cy in range(FIELD_SIZE):
            if h[n] != 0:
                under_flag = False

            ch = h[n] + abs(x[n] - cx) + abs(y[n] - cy)
            if H[cx][cy] == -1:
                H[cx][cy] = ch
            elif under_flag and H[cx][cy] <= ch:
                H[cx][cy] = ch
            elif H[cx][cy] == ch:
                H[cx][cy] = ch
            else:
                H[cx][cy] = None

for cx in range(FIELD_SIZE):
    for cy in range(FIELD_SIZE):
        if H[cx][cy] is not None:
            print(cx, cy, H[cx][cy])