Problem: In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.   The pyramid had _center coordinates_ (C_X, C_Y) and _height_ H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).  Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:    * C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.    * Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."   This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Submission attempts (in order):
N = int(input())
Xs = [list(map(int, input().split(" "))) for _ in range(N)]
"""
input = ["2 3 5","2 1 5","1 2 5","3 2 5"]
input = ["0 0 100", "1 1 98"]
input = ["99 1 191", "100 1 192", "99 0 192"]
Xs = [list(map(int, x.split(" "))) for x in input]
"""

Xs.sort(key=lambda x:x[2], reverse=True)


def solv(Xs):
    for x in range(101):
        for y in range(101):
            #Cx, Cy, h = tuple(Xs[0])
            #H = h + abs(x - Cx) + abs(y - Cy)
            for Cx, Cy, h in Xs:
                H = h + abs(x - Cx) + abs(y - Cy)
                if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                    break
            else:
                return (x, y, H)


print("%d %d %d" % solv(Xs))


"""
N = int(input())
Xs = [list(map(int, input().split(" "))) for _ in range(N)]
"""
input = ["2 3 5","2 1 5","1 2 5","3 2 5"]
input = ["0 0 100", "1 1 98"]
input = ["99 1 191", "100 1 192", "99 0 192"]
Xs = [list(map(int, x.split(" "))) for x in input]

Xs.sort(key=lambda x:x[2], reverse=True)


def solv(Xs):
    for x in range(101):
        for y in range(101):
            Cx, Cy, h = tuple(Xs[0])
            H = h + abs(x - Cx) + abs(y - Cy)
            for Cx, Cy, h in Xs:
                if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                    break
            else:
                return (x, y, H)


print("%d %d %d" % solv(Xs))


N = int(input())
Xs = [list(map(int, input().split(" "))) for _ in range(N)]
"""
input = ["2 3 5","2 1 5","1 2 5","3 2 5"]
input = ["0 0 100", "1 1 98"]
input = ["99 1 191", "100 1 192", "99 0 192"]
Xs = [list(map(int, x.split(" "))) for x in input]
"""

Xs.sort(key=lambda x:x[2], reverse=True)


def solv(Xs):
    for x in range(101):
        for y in range(101):
            Cx, Cy, h = tuple(Xs)
            H = h + abs(x - Cx) + abs(y - Cy)
            for Cx, Cy, h in Xs:
                if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                    break
            else:
                return (x, y, H)


print("%d %d %d" % solv(Xs))


N = int(input())
Xs = [list(map(int, input().split(" "))) for _ in range(N)]
"""
input = ["2 3 5","2 1 5","1 2 5","3 2 5"]
input = ["0 0 100", "1 1 98"]
input = ["99 1 191", "100 1 192", "99 0 192"]
"""
Xs = [list(map(int, x.split(" "))) for x in input]
Xs.sort(key=lambda x:x[2], reverse=True)

for x in range(101):
    for y in range(101):
        h= Xs[0][2]
        Cx = Xs[0][0]
        Cy = Xs[0][1]
        H = h + abs(x - Cx) + abs(y - Cy)
        for i in range(len(Xs)):
            if H - abs(x - Xs[i][0]) - abs(y - Xs[i][1]) != Xs[i][2]:
                break
            if i == len(Xs)-1:
                print("%d %d %d" % (x, y, H))


N = int(input())
Xs = [list(map(int, input().split(" "))) for _ in range(N)]
"""
input = ["2 3 5","2 1 5","1 2 5","3 2 5"]
input = ["0 0 100", "1 1 98"]
input = ["99 1 191", "100 1 192", "99 0 192"]
Xs = [list(map(int, x.split(" "))) for x in input]
"""

Xs.sort(key=lambda x:x[2], reverse=True)


def solv(Xs):
    for x in range(101):
        for y in range(101):
            Cx, Cy, h = tuple(Xs[0])
            H = h + abs(x - Cx) + abs(y - Cy)
            for Cx, Cy, h in Xs:
                if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                    break
            else:
                return (x, y, H)


print("%d %d %d" % solv(Xs))


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted