Problem p03240 (python)

Fixed submission:
def calcCh(cx, cy, x, y, h):
    return abs(x-cx)+abs(y-cy)+h
def calcH(cx, cy, ch, x, y, h):
    return max(ch - calcCh(cx, cy, x, y, 0), 0)
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
xyh = sorted(xyh, key = lambda x: x[2])[::-1]
lst = [[x, y] for x in range(101) for y in range(101)]
for Cx, Cy in lst:
    Ch = calcCh(Cx, Cy, *xyh[0])
    if all(xyh[i][2] == calcH(Cx, Cy, Ch, *xyh[i]) for i in range(n)):
        break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
lst = [[x, y] for x in range(101) for y in range(101)]
for i, j in lst:
    k = 0
    flag = True
    for x, y, h in xyh:
        H_ = calcH(x, i, y, j, h)
        if H_ > Hmax and h != 0:
            flag = False
            break
        if k > 0:
            if H_ != H and flag and h != 0:
                flag = False
                break
            elif H_ != H and not flag and h == 0:
                if H_ < H:
                    H = H_
            elif H_ != H and h == 0:
                if H_ <= H:
                    flag = False
                    break
            elif H_ != H:
                H = H_
                flag = True
            else:
                flag = True
        else:
            H = H_
            if h == 0 and n == 1:
                flag = False
        k += 1
    if k < n or H > Hmax:
        continue
    else:
        Cx = i
        Cy = j
        Ch = H
    break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
lst = [[x, y] for x in range(101) for y in range(101)]
for i, j in lst:
    k = 0
    flag = True
    for x, y, h in xyh:
        H_ = calcH(x, i, y, j, h)
        if k > 0:
            if H_ != H and flag and h != 0:
                flag = False
                break
            elif H_ != H and h == 0:
                continue
            elif H_ != H:
                H = H_
                flag = True
            else:
                flag = True
                continue
        else:
            H = H_
        if h == 0 and k != n-1:
            flag = False
        k += 1
    if flag == False or H > Hmax:
        continue
    else:
        Cx = i
        Cy = j
        Ch = H
    break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
lst = [[x, y] for x in range(101) for y in range(101)]
for i, j in lst:
    k = 0
    flag = True
    for x, y, h in xyh:
        H_ = calcH(x, i, y, j, h)
        if k > 0:
            if H_ != H and flag and h != 0:
                flag = False
                break
            elif H_ != H and h == 0:
                continue
            elif H_ != H:
                H = H_
                flag = True
            else:
                flag = True
                continue
        else:
            H = H_
        if h == 0 and n != 1:
            flag = False
        k += 1
    if flag == False or H > Hmax:
        continue
    else:
        Cx = i
        Cy = j
        Ch = H
    break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
lst = [[x, y] for x in range(101) for y in range(101)]
for i, j in lst:
    k = 0
    flag = True
    for x, y, h in xyh:
        H_ = calcH(x, i, y, j, h)
        if h == 0 and n != 1:
            flag = False
        if k > 0:
            if H_ != H and flag:
                flag = False
                break
            elif H_ != H:
                H = H_
                flag = True
            else:
                flag = True
                continue
        else:
            H = H_
        k += 1
    if flag == False or H > Hmax:
        continue
    else:
        Cx = i
        Cy = j
        Ch = H
    break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
lst = [[x, y] for x in range(101) for y in range(101)]
for i, j in lst:
    k = 0
    flag = True
    for x, y, h in xyh:
        H_ = calcH(x, i, y, j, h)
        if h == 0:
            flag = False if n != 1
        if k > 0:
            if H_ != H and flag:
                flag = False
                break
            elif H_ != H:
                H = H_
                flag = True
            else:
                flag = True
                continue
        else:
            H = H_
        k += 1
    if flag == False or H > Hmax:
        continue
    else:
        Cx = i
        Cy = j
        Ch = H
    break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
for i in range(101):
    for j in range(101):
        k = 0
        flag = True
        for x, y, h in xyh:
            H_ = calcH(x, i, y, j, h)
            if h == 0:
                flag = False if n != 1
            if k > 0:
                if H_ != H and flag:
                    flag = False
                    break
                elif H_ != H:
                    H = H_
                    flag = True
                else:
                    flag = True
                    continue
            else:
                H = H_
            k += 1
        if flag == False or H > Hmax:
            continue
        else:
            Cx = i
            Cy = j
            Ch = H
            break
    else:
        continue
    break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
for i in range(101):
    for j in range(101):
        k = 0
        flag = True
        for x, y, h in xyh:
            H_ = calcH(x, i, y, j, h)
            if h == 0:
                flag = False
            if k > 0:
                if H_ != H and flag:
                    flag = False
                    break
                elif H_ != H:
                    H = H_
                    flag = True
                else:
                    flag = True
                    continue
            else:
                H = H_
                flag = True
            k += 1
        if flag == False or H > Hmax:
            continue
        else:
            Cx = i
            Cy = j
            Ch = H
            break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
for i in range(101):
    for j in range(101):
        k = 0
        flag = True
        for x, y, h in xyh:
            H_ = calcH(x, i, y, j, h)
            if h == 0:
                flag = False
            if k > 0:
                if H_ != H and flag:
                    flag = False
                    break
                elif H_ != H:
                    H = H_
                    flag = True
                else:
                    flag = True
                    continue
            else:
                H = H_
            k += 1
        if flag == False or H > Hmax:
            continue
        else:
            Cx = i
            Cy = j
            Ch = H
            break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9
for i in range(101):
    for j in range(101):
        k = 0
        flag = True
        for x, y, h in xyh:
            H_ = calcH(x, i, y, j, h)
            if h == 0:
                flag = False
            if k > 0:
                if H_ != H and flag:
                    flag = False
                    break
                elif H_ != H:
                    H = H_
                    flag = True
                else:
                    continue
            else:
                H = H_
            k += 1
        if flag == False or H > Hmax:
            continue
        else:
            Cx = i
            Cy = j
            Ch = H
            break
print(Cx, Cy, Ch)

Buggy submission (verdict: Runtime Error):
def calcH(x, cx, y, cy, h):
    return abs(x-cx)+abs(y-cy)+h
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
Hmax = 10**9 + 1
for i in range(101):
    for j in range(101):
        k = 0
        flag = True
        for x, y, h in xyh:
            H_ = calcH(x, i, y, j, h)
            if h == 0:
                flag = False
            if k > 0:
                if H_ != H and flag:
                    flag = False
                    break
                elif H_ != H:
                    H = H_
                    flag = True
                else:
                    continue
            else:
                H = H_
            k += 1
        if flag == False:
            continue
        else:
            Cx = i
            Cy = j
            Ch = H
            break
print(Cx, Cy, Ch)