Problem:


Score: 300 points

Problem Statement

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.  

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:  

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.  

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.  

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.  



Sample input:
4
2 3 5
2 1 5
1 2 5
3 2 5


Sample output:
2 2 6

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# H, W, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# S = input()

# d = sorted(d, reverse=True, key=lambda x:x[0])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

data = []
for i in range(N):
    data.append(list(map(int, input().split())))
data = sorted(data, reverse=True, key=lambda x:x[2])

ans_x = 0
ans_y = 0
ans_h = 0
for i in range(101):
    for j in range(101):
        H = -1
        for l in data:
            if H == -1:
                _ = l[2] + abs(l[0] - i) + abs(l[1] - j)
                H = _
            else:
                h_i_cal = max(H - abs(l[0] - i) - abs(l[1] - j), 0)
                if h_i_cal != l[2]:
                    break
        else:
            ans_x = i
            ans_y = j
            ans_h = H

print(ans_x, ans_y, ans_h)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *XYH = map(int, read().split())

    for x, y, h in zip(*[iter(XYH)] * 3):
        if h != 0:
            x0, y0, h0 = x, y, h

    for cx in range(101):
        for cy in range(101):
            H = h0 + abs(x0 - cx) + abs(y0 - cy)
            ok = True
            for x, y, h in zip(*[iter(XYH)] * 3):
                if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                    ok = False
                    break
            if ok:
                print(cx, cy, H)
                return

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *XYH = map(int, read().split())

    for cx in range(101):
        for cy in range(101):
            ok = 10 ** 9 + 100
            ng = 0
            while ok - ng > 1:
                mid = (ok + ng) // 2
                valid = True
                for x, y, h in zip(*[iter(XYH)] * 3):
                    if max(mid - abs(x - cx) - abs(y - cy), 0) < h:
                        valid = False
                        break
                if valid:
                    ok = mid
                else:
                    ng = mid
            H = ok
            valid = True
            for x, y, h in zip(*[iter(XYH)] * 3):
                if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                    valid = False
                    break
            if valid:
                print(cx, cy, H)
                return

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)

for cx in range(0,101):
    for cy in range(0,101):
        x,y,h=xyh[0]
        H=h+abs(x-cx)+abs(y-cy)
        if H<0:
            continue

        for i in range(1,n):
            x,y,h=xyh[i]

            if h!=max(H-abs(x-cx)-abs(y-cy),0):
                break
        else:
            print('{} {} {}'.format(cx,cy,H))
            exit(0)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    xyh = [None] * N
    for i in range(N):
        xyh[i] = tuple(map(int, input().split()))

    for i in range(N):
        if xyh[i][2] > 0:
            Bx, By, Bh = xyh[i]
            break

    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = Bh + abs(Bx - Cx) + abs(By - Cy)
            is_ok = True
            for x, y, h in xyh:
                if max(H - abs(x - Cx) - abs(y - Cy), 0) != h:
                    is_ok = False
                    break
            if is_ok:
                print(Cx, Cy, H)
                exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n = ii()
    x = [0]*n
    y = [0]*n
    h = [0]*n
    for i in range(n):
        x[i], y[i], h[i] = mi()
    idx = h.index(max(h))
    for cx in range(101):
        for cy in range(101):
            flag = True
            H = abs(cx-x[idx])+abs(cy-y[idx])+h[idx]
            for i in range(n):
                tmp = abs(cx-x[i])+abs(cy-y[i])
                if h[i] == 0:
                    flag &= (tmp >= H)
                else:
                    tmp += h[i]
                    flag &= (tmp==H)
            if flag:
                print(cx, cy, H)
                return
            
            
        
        




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
z=[]
aa=[]
for i in range(n):
     z.append(list(map(int,input().split())))
for cx in range(101):
    for cy in range(101):
        ans=set()
        for i in range(n):
            x,y,h=z[i][0],z[i][1],z[i][2]
            if h!=0:
                tmp=h+abs(x-cx)+abs(y-cy)
                ans.add(tmp)
        if len(ans)==1:
            ans=list(ans)
            aa.append((ans[0],cx,cy))

for a,cx,cy in aa:
    flg=True
    for i in range(n):
        x,y,h=z[i][0],z[i][1],z[i][2]
        if h!=max(a-abs(x-cx)-abs(y-cy),0):
                flg=False
    if flg:
        print(cx,cy,a)
        exit()

Submission status: Accepted

Solution code:
n,*xyh = map(int,open(0).read().split())
a = sorted([(xyh[i*3],xyh[i*3+1],xyh[i*3+2]) for i in range(n)],key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    dh = abs(a[0][0]-i)+abs(a[0][1]-j)+a[0][2]
    for x,y,h in a[1:]:
      if h != max(dh-abs(x-i)-abs(y-j),0):
        break
    else:
      print(i,j,dh)
      exit()

Submission status: Accepted

Solution code:
n=int(input())
ar=[]
def g(i):
    return i[2]
for _ in range(n):
    a,b,c=map(int,input().strip().split(" "))
    ar.append((a,b,c))
ar.sort(key=g,reverse=True)

for x in range(101):
    for y in range(101):
        t=1
        p=(x,y)
        h=0
        for i in range(n):
            if h==0:
                h=ar[i][2]+abs(ar[i][0]-x)+abs(ar[i][1]-y)
            elif ar[i][2]>0:
                c_h=ar[i][2]+abs(ar[i][0]-x)+abs(ar[i][1]-y)
                if c_h!=h:
                    t=0
                    break
            else:
                if h-(abs(ar[i][0]-x)+abs(ar[i][1]-y))>0:
                    t=0
                    break
        if t==1:
            ans=(x,y,h)
            break
for i in ans:
    print(i,end=" ")

Submission status: Accepted

Solution code:
n = int(input())
exprs = []

for _ in range(n):
    exprs.append([int(i) for i in input().split()])

exprs = sorted(exprs, key=lambda x: -x[2])

for cx in range(0, 101):
    for cy in range(0, 101):
        x0, y0, h0 = exprs[0]
        ch = h0 + abs(x0 - cx) + abs(y0 - cy)
        for x, y, h in exprs[1:]:
            if h != max(ch - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(cx, cy, ch)
            quit()

Submission status: Accepted

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def judge(id, sho, n):
    hito = [0]
    for i in range(n):
        if id % 2 == 1:
            hito.append(1)
        else:
            hito.append(0)
        id //= 2

    for i, h in enumerate(hito):
        if i == 0:
            continue
        if h == 1:
            for x, y in sho[i-1]:
                if hito[x] != y:
                    return -1

    return sum(hito)


def solve():
    n = getN()
    q = []
    for i in range(n):
        q.append(getList())

    q.sort(key=lambda x: -x[2])
    for i in range(0, 101):
        for j in range(0, 101):
            ch = -1
            ok = True
            
            for x, y, h in q:
                ins = h + abs(x-i) + abs(y-j)
                if ch == -1:
                    ch = ins
                else:
                    if ch != ins:
                        if h != 0:
                            ok = False
                            break
                        if h == 0 and ins < ch:
                            ok = False
                            break
            if ok:
                print(i, j, ch)
                return



def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
import sys

n=int(input())
xyh=[[] for i in range(n)]
for i in range(n):
    x,y,h=map(int,input().split())
    xyh[i].append(x)
    xyh[i].append(y)
    xyh[i].append(h)
for i in range(101):
    for j in range(101):
        f=0
        dis=[[i] for i in range(205)]
        for q in range(n):
            x=xyh[q][0]
            y=xyh[q][1]
            h=xyh[q][2]
            d=abs(x-i)+abs(y-j)
            
            if len(dis[d])==1:
                dis[d].append(h)
            elif len(dis[d])!=1 and dis[d][1]!=h:
                f=1
        
        dis=[dis[e] for e in range(205) if len(dis[e])!=1]
        m=len(dis)
        if m==1 and f==0:
            print(i,j,dis[0][0]+dis[0][1])
            sys.exit()
            
        else:
            if all(dis[e][0]+dis[e][1]==dis[e+1][0]+dis[e+1][1] for e in range(m-1) if dis[e+1][1]!=0) and f==0:
                print(i,j,dis[0][0]+dis[0][1])
                sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    _ = list(map(int, input().split()))
    a.append(_)
a = sorted(a, key=lambda x:x[2],reverse = True)

check = False
    
for i in range(101):
    for j in range(101):
        b = 0
        while b < n:
            if b == 0:
                h = abs(i - a[b][0]) + abs(j - a[b][1]) + a[b][2]
                b +=1
            else:
                de = max(h - abs(i - a[b][0]) - abs(j - a[b][1]),0)
                if de == a[b][2]:
                    b+=1
                else:
                    break
        if b == n:
            ans = str(i) + ' ' + str(j) + ' ' +str(h)
            check = True
        if check:
            break
    if check:
        break
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
xyh=[list(map(int,input().strip().split())) for _ in range(N)]

dp=[[-1 for i in range(101)] for j in range(101)]
for n in range(N):
    dp[xyh[n][0]][xyh[n][1]]=xyh[n][2]

def find_top(x,y,N,xyh):
    find=True
    prev=-1
    for n in range(N):
        if xyh[n][2]!=0:
            top=xyh[n][2]+abs(xyh[n][0]-x)+abs(xyh[n][1]-y)
            if prev==-1:
                prev=top
            else:
                if prev!=top:
                    find=False
                    break
    return find,top

def check_top(x,y,top,N,xyh):
    check=True
    for n in range(N):
        if xyh[n][2]==0:
            if top-abs(xyh[n][0]-x)-abs(xyh[n][1]-y)>0:
                check=False
                break
    return check

fin=False
for x in range(101):
    if fin==True:
        break
    for y in range(101):
        find=find_top(x,y,N,xyh)[0]
        height=find_top(x,y,N,xyh)[1]
        if find and height>=1 and check_top(x,y,height,N,xyh):
            print("{} {} {}".format(x,y,height))
            fin=True

Submission status: Accepted

Solution code:
import sys

N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]

# 仮の高さを計算する
for x, y, h in XYH:
    if h != 0:
        px, py, ph = x, y, h
        break

for cx in range(0, 101):
    for cy in range(0, 101):
        # 仮の高さ
        H = ph + abs(cx - px) + abs(cy - py)

        for x, y, h in XYH:
            if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                break
        else:
            print(cx, cy, H)
            sys.exit()

Submission status: Accepted

Solution code:
#Pythonのままだときびしい？
#100*100*200*100
n=int(input())
x=[-1]*n
y=[-1]*n
h=[-1]*n
for i in range(n):
  x[i],y[i],h[i]=map(int,input().split())

mh=max(h)
for cx in range(0,101):
  for cy in range(0,101):
    for H in range(mh,mh+216):
      if all(h[j]==max(H-abs(cx-x[j])-abs(cy-y[j]),0) for j in range(n)):
        print(cx,cy,H)
        exit()

Submission status: Accepted

Solution code:
n=int(input())
x=[-1]*n
y=[-1]*n
h=[-1]*n
for i in range(n):
  x[i],y[i],h[i]=map(int,input().split())

mh=max(h)
for cx in range(0,101):
  for cy in range(0,101):
    for H in range(mh,mh+216):
      if all(h[j]==max(H-abs(cx-x[j])-abs(cy-y[j]),0) for j in range(n)):
        print(cx,cy,H)
        exit()

Submission status: Accepted

Solution code:
n=int(input())
x=[-1]*n
y=[-1]*n
h=[-1]*n
for i in range(n):
  x[i],y[i],h[i]=map(int,input().split())
  
cnt=0
now=0
for i in range(n):
  if h[i]>0:
    cnt+=1
    now=i
if cnt==1:
  print(x[now],y[now],h[now])
  exit()

for cx in range(0,101):
  for cy in range(0,101):
    H=[]
    for i in range(n):
      if h[i]>0:
        H.append(h[i]+abs(cx-x[i])+abs(cy-y[i]))
    if len(set(H))==1:
      print(cx,cy,H[0])
      exit()

Submission status: Accepted

Solution code:
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]

for i in range(101):
    for j in range(101):
        temp = -1
        for x, y, h in XYH:
            if h == 0:
                continue
            temp = h + abs(x - i) + abs(y - j)
            break
        flag = 0
        for x, y, h in XYH:
            kouho = temp - (abs(x - i) + abs(y - j)) - h
            if kouho == 0:
                continue
            elif h == 0 and kouho < 0:
                continue
            else:
                flag = 1
                break
        if not flag:
            print(i, j, temp)
            exit()

Submission status: Accepted

Solution code:
# 何となく分かったが、0の扱いが結構怪しい、解き直し必要

n = int(input())

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

for i in range(101):
    for j in range(101):
        h = xyh[0][2] + abs(xyh[0][0] - i) + abs(xyh[0][1] - j)
        flag = True
        for k in range(1, n):
            if xyh[k][2] == 0:
                if abs(xyh[k][0] - i) + abs(xyh[k][1] - j) < h:
                    flag = False
                    break
            else:
                temp = xyh[k][2] + abs(xyh[k][0] - i) + abs(xyh[k][1] - j)
                if h != temp:
                    flag = False
                    break
        if flag == True and h >= 1:
            print(i, j, h)
            exit()

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(101):
    for j in range(101):
        h = xyh[0][2] + abs(xyh[0][0] - i) + abs(xyh[0][1] - j)
        flag = True
        for k in range(1, n):
            if xyh[k][2] == 0:
                if abs(xyh[k][0] - i) + abs(xyh[k][1] - j) < h:
                    flag = False
                    break
            else:
                temp = xyh[k][2] + abs(xyh[k][0] - i) + abs(xyh[k][1] - j)
                if h != temp:
                    flag = False
                    break
        if flag == True and h >= 1:
            print(i, j, h)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int, input().split())))
xyh.sort(key = lambda x: x[2], reverse = True)
for i in range(101):
    for j in range(101):
        h = xyh[0][2] + abs(xyh[0][0] - i) + abs(xyh[0][1] - j)
        flag = True
        for k in range(1, n):
            if xyh[k][2] == 0:
                if abs(xyh[k][0] - i) + abs(xyh[k][1] - j) < h:
                    flag = False
                    break
            else:
                temp = xyh[k][2] + abs(xyh[k][0] - i) + abs(xyh[k][1] - j)
                if h != temp:
                    flag = False
                    break
        if flag == True and h >= 1:
            print(i, j, h)
            break
    if flag == True:
        break

Submission status: Accepted

Solution code:
from itertools import product


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

for cx, cy in product(range(101), repeat=2):
    x0, y0, h0 = xyh[0]
    ch = h0 + abs(x0 - cx) + abs(y0 - cy)
    for x, y, h in xyh:
        if h != max(ch - abs(x - cx) - abs(y - cy), 0):
            break
    else:
        print(cx, cy, ch)
        break

Submission status: Accepted

Solution code:
N = int(input())

xyh = []
for i in range(N):
    xyh.append(list(map(int,input().split())))

xyh_sorted = sorted(xyh, key=lambda x: x[2], reverse=True)

answer = [0, 0, 0]
for cy in range(0, 101):
    for cx in range(0, 101):
        H = xyh_sorted[0][2] + abs(xyh_sorted[0][0] - cx) + abs(xyh_sorted[0][1] - cy)
        flag = True
        for i in range(1,N):
            h2 = max(H - abs(xyh_sorted[i][0] - cx) - abs(xyh_sorted[i][1] - cy), 0)
            if h2 != xyh_sorted[i][2]:
                flag = False
                break
        if flag:
            answer = [cx, cy, H]
            break
    if flag:
        break

answerString = str(answer[0]) + " " + str(answer[1]) + " " + str(answer[2])
print(answerString)

Submission status: Accepted

Solution code:
N = int(input())

Info = [[] for T in range(0,N)]
for I in range(0,N):
    Info[I] = [int(T) for T in input().split()]
Info = sorted(Info,reverse=True,key=lambda X:X[2])
for CX in range(0,101):
    for CY in range(0,101):
        Flag  = True
        BaseH = abs(Info[0][0]-CX)+abs(Info[0][1]-CY)+Info[0][2]
        for I in range(1,N):
            if max(BaseH-abs(Info[I][0]-CX)-abs(Info[I][1]-CY),0)!=Info[I][2]:
                Flag = False
                break
        if Flag:
            Ans = [str(CX),str(CY),str(BaseH)]
            break
    if Flag:
        break
print(' '.join(Ans))

Submission status: Accepted

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def is_consistent(cx, cy, X, Y, H, N):
    h_proposal = None
    max_h = math.inf
    for i in range(N):
        if H[i] > 0:
            if h_proposal is not None and h_proposal != H[i]+abs(X[i]-cx)+abs(Y[i]-cy):
                return None
            h_proposal = H[i]+abs(X[i]-cx)+abs(Y[i]-cy)
        else:
            max_h = min(max_h, abs(X[i]-cx)+abs(Y[i]-cy))
    if h_proposal is not None and h_proposal <= max_h:
        return cx, cy, h_proposal

def solve():
    N = read_int()
    X, Y, H = [], [], []
    for _ in range(N):
        x, y, h = read_ints()
        X.append(x)
        Y.append(y)
        H.append(h)
    # h == max(H-abs(x-cx)-abs(y-cy), 0)
    for cx in range(101):
        for cy in range(101):
            answer = is_consistent(cx, cy, X, Y, H, N)
            if answer is not None:
                return answer


if __name__ == '__main__':
    print(*solve())

Submission status: Accepted

Solution code:
import sys
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
  if xyh[i][2] != 0:
    cnt += 1
if cnt == 1:
  for i in range(n):
    if xyh[i][2] != 0:
      print(" ".join(list(map(str, xyh[i]))))
      sys.exit()
for i in range(101):
  for j in range(101):
    x = []
    for k in range(n):
      if xyh[k][2] != 0:
        x.append(abs(xyh[k][0]-i)+abs(xyh[k][1]-j)+xyh[k][2])
    if len(set(x)) == 1:
      print(i, j, x[0])

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split())) for n in range(N)]
xyh.sort(key=lambda x:x[2],reverse=True)#高度１でない情報から高さ定めるため
for X in range(0,101):
    for Y in range(0,101):
        H = xyh[0][2] + abs(xyh[0][0]-X) + abs(xyh[0][1]-Y)
        for i in range(1,N):
            x,y,h = xyh[i]
            if h != max(H - abs(x-X) -abs(y-Y),0):
                break
        else:
            print(X,Y,H)
            break

Submission status: Accepted

Solution code:
N = int(input())

XYs = []
for _ in range(N):
  XYs.append(list(map(int, input().split())))
  
for i in range(101):
  for j in range(101):
    f = 1
    for k in range(N):
      if XYs[k][2] > 0:
        h = XYs[k][2] + abs(XYs[k][0]-i) + abs(XYs[k][1]-j)
        break
    for k in range(N):
      if max(h - abs(XYs[k][0]-i) - abs(XYs[k][1]-j), 0) != XYs[k][2]:
        f = 0
        break
    if f == 1:
      print(i,j,h)
      exit()

Submission status: Accepted

Solution code:
import sys

N = int(input())
xyz = [list(map(int, input().split())) for _ in range(N)]

idx = 0
for i in range(N):
    if xyz[i][2] != 0:
        idx = i
        break

for cx in range(101):
    for cy in range(101):
        switch = 1
        H = xyz[idx][2] + abs(xyz[idx][0] - cx) + abs(xyz[idx][1] - cy)
        for x,y,h in xyz:
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                switch = 0
                break
        if switch == 1:
            print(cx, cy, H)
            sys.exit()

Submission status: Accepted

Solution code:
import sys

N = int(input())
xyz = [list(map(int, input().split())) for _ in range(N)]

idx = 0
for i in range(N):
    if xyz[i][2] != 0:
        idx = i
        break

for cx in range(101):
    for cy in range(101):
        switch = 1
        distance = abs(xyz[idx][0] - cx) + abs(xyz[idx][1] - cy)
        H = xyz[idx][2] + distance
        
        for x,y,h in xyz:
            karidis = abs(x - cx) + abs(y - cy)
            if h == 0 and distance <= karidis:
                continue
            kari = h + karidis
            if H != kari:
                switch = 0
                break
        if switch == 1:
            print(cx, cy, H)
            sys.exit()

Submission status: Accepted

Solution code:
n = int(input())

x = [0] * n
y = [0] * n
h = [0] * n

for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())

for cx in range(101):
    for cy in range(101):
        H = -1
        for i in range(n):
            if h[i] == 0:
                pass
            else:
                tmp = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
                H = tmp
                break
        flag = True
        for i in range(n):
            if h[i] != max(H-abs(x[i]-cx)-abs(y[i]-cy),0):
                flag = False
                break
        if flag:
            print(cx,cy,H)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc112/tasks/abc112_c
import sys
n = int(input())
pyramid = []
ch = 1
for _ in range(n):
    x, y, h = map(int, input().split())
    pyramid.append((x, y, h))
    ch = max(ch, h)

def cal(cx, cy, ch, x, y, h):
    height = max(ch - abs(x - cx) - abs(y - cy), 0)
    return height == h

while True:
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            for x, y, h in pyramid:
                if not cal(cx, cy, ch, x, y, h):
                    break
            else:
                print(cx, cy, ch)
                sys.exit()
    ch += 1

Submission status: Accepted

Solution code:
n = int(input())
s_list = []

for i in range(n):
    x,y,h = map(int,input().split())
    s_list.append([x,y,h])

s_list.sort(key=lambda x: x[2])
s_list = list(reversed(s_list))

H = 0
flag = 0

for i in range(101):
    for j in range(101):
        flag = 0
        H = s_list[0][2] + abs(i-s_list[0][0]) + abs(j-s_list[0][1])
        for k in range(1,n):
            if s_list[k][2] != max(H - abs(s_list[k][0]-i) - abs(s_list[k][1]-j),0):
                flag = 1
                break
        if flag == 0:
            print(i,j,H)
            break

Submission status: Accepted

Solution code:
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
#print(XYH)

for x1, y1, h1 in XYH:
    if h1 > 0:
        for Cx in range(101):
            for Cy in range(101):
                H = h1 + abs(x1 - Cx) + abs(y1 - Cy)
                # print(Cx, Cy, H)
                if all(h == max(H - abs(x - Cx) - abs(y - Cy), 0) for x, y, h in XYH):
                  print(Cx, Cy, H)
                  exit()

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
x = [0]*n
y = [0]*n
h = [0]*n

for i in range(n):
    x[i], y[i], h[i] = MAP()

for i in range(101):
    for j in range(101):
        H = 0
        for k in range(n):
            if h[k] != 0:
                if H == 0 or H == h[k] + abs(x[k]-i) + abs(y[k]-j):
                    H = h[k] + abs(x[k]-i) + abs(y[k]-j)
                else:
                    break
        else:
            for k in range(n):
                if h[k] == 0:
                    if H - abs(x[k]-i) - abs(y[k]-j) <= 0:
                        continue
                    else:
                        break
            else:
                print(i,j,H)

Submission status: Accepted

Solution code:
N = int(input())
P = [list(map(int,input().split())) for n in range(N)]
x,y,h = list(filter(lambda x:x[2],P))[0]

for i in range(101):
  for j in range(101):
    H = h+abs(x-i)+abs(y-j)
    if all(max(H-abs(t[0]-i)-abs(t[1]-j),0)==t[2] for t in P):
      print(i,j,H)