Problem p03240 (python)

Fixed submission:
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh = sorted(xyh, key=lambda x:(x[2]), reverse=True)

ans = -1, -1, -1
for cx in range(101):
    for cy in range(101):
        flg = True
        x, y, h = xyh[0][0], xyh[0][1], xyh[0][2]
        ch = abs(cx-x) + abs(cy-y) + h
        for i in range(1,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            tmph = max(ch - abs(cx-x) - abs(cy-y), 0)
            if h != tmph:
                flg = False
                break
        if flg:
            ans = cx, cy, ch
print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh = sorted(xyh, key=lambda x:(x[2]))

for cx in range(101):
    for cy in range(101):
        flg = True
        x, y, h = xyh[0][0], xyh[0][1], xyh[0][2]
        ch = abs(cx-x) + abs(cy-y) + h
        # print(cx, cy, ch)
        for i in range(1,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            tmph = max(ch - abs(cx-x) - abs(cy-y), 0)
            if h != tmph:
                flg = False
                break
        if flg:
            ans = cx, cy, ch
            break
    if flg:
        break
print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh = sorted(xyh, key=lambda x:(x[2]))

for cx in range(101):
    for cy in range(101):
        flg = True
        x, y, h = xyh[0][0], xyh[0][1], xyh[0][2]
        ch = abs(cx-x) + abs(cy-y) + h
        # print(cx, cy, ch)
        for i in range(1,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            tmph = max(ch - abs(cx-x) - abs(cy-y), 0)
            if h != tmph:
                flg = False
                break
        if flg:
            ans = cx, cy, ch
            # break
    if flg:
        break
print(*ans)

Buggy submission (verdict: Runtime Error):
def calc_ch(cx, cy, i):
    x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
    ch = max(abs(cx-x) + abs(cy-y) + h, 0)
    if h == 0 or ch == 0:
        if i == n-1:
            ch, i = -1, -1
        else:
            ch, i = calc_ch(cx, cy, i+1)
    return ch, i


n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
# xyh = sorted(xyh, key=lambda x:(x[2]))

for cx in range(101):
    for cy in range(101):
        flg = False
        ch0, s = calc_ch(cx, cy, 0)
        # print(cx, cy, ch0)
        if ch0 == -1:
            continue
        for i in range(s,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            if h == 0:
                continue
            ch = max(abs(cx-x) + abs(cy-y) + h, 0)
            if ch != ch0:
                break
            if i == n-1:
                flg = True
        if flg:
            anscx, anscy = cx, cy
            ansh = ch0
            break
    if flg:
        break
# print(cx, cy)
print(anscx, anscy, ch0)

Buggy submission (verdict: Runtime Error):
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh = sorted(xyh, key=lambda x:(x[2]), reverse=True)

for cx in range(101):
    for cy in range(101):
        flg = True
        x, y, h = xyh[0][0], xyh[0][1], xyh[0][2]
        ch0 = max(abs(cx-x) + abs(cy-y) + h, 0)
        for i in range(1,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            ch = max(abs(cx-x) + abs(cy-y) + h, 0)
            if ch > 0 and ch != ch0:
                flg = False
                break
        if flg:
            anscx, anscy = cx, cy
            ansh = ch0
            break
    if flg:
        break

print(anscx, anscy, ch0)

Buggy submission (verdict: Runtime Error):
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flg = True
        x, y, h = xyh[0][0], xyh[0][1], xyh[0][2]
        ch0 = max(abs(cx-x) + abs(cy-y) + h, 0)
        for i in range(1,n):
            x, y, h = xyh[i][0], xyh[i][1], xyh[i][2]
            ch = max(abs(cx-x) + abs(cy-y) + h, 0)
            if ch != ch0:
                flg = False
                break
        if flg:
            anscx, anscy = cx, cy
            ansh = ch0
            break
    if flg:
        break

print(anscx, anscy, ch0)