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:
N=int(input())
field=[[0 for _ in range(101)] for _ in range(101)]

p=[list(map(int,input().split())) for _ in range(N)]
for x,y,h in p:
    if h!=0:
        tem_x=x
        tem_y=y
        tem_h=h
        break

for i in range(101):
    for k in range(101):
        flag=True
        H=tem_h+abs(tem_x-i)+abs(tem_y-k)
        for x,y,h in p:
            if h==max(H-abs(x-i)-abs(y-k),0):
                pass
            else:
                flag=False
        if flag:
            print(i,k,H)
            exit()

Submission status: Accepted

Solution code:
N = int(input())

xyh_list = list()

for i in range(N):
    x,y,h = map(int, input().split())
    xyh_list.append((x,y,h))
    
for i in range(N):
    h = xyh_list[i][2]
    if h != 0:
        no_zero_h = i
        break


break_flag = 0

for i in range(0,101):
    for j in range(0,101):
        
        x = xyh_list[no_zero_h][0]
        y = xyh_list[no_zero_h][1]
        h = xyh_list[no_zero_h][2]
        H = h + abs(x-i) + abs(y-j)
        
        if 1 <= H:
            for k in range(0,N):
                x = xyh_list[k][0]
                y = xyh_list[k][1]
                h = xyh_list[k][2]
                
                if (h != 0 and h + abs(x-i) + abs(y-j) != H) or (h == 0 and H - abs(x-i) - abs(y-j) > 0):
                    break
            else:
                print(i,j,H)
                break_flag = 1
                
        if break_flag == 1:
            break
            
    if break_flag == 1:
        break

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input())

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

xyh.sort(key=itemgetter(2),reverse=True)
for h in xyh:
    if h[2]==0:
        count+=1
for px in range(101):
    for py in range(101):
        judge=0
        base=0
        for i in xyh:
            if i[2]>=1:
                if base==0:
                    base=i[2]+abs(i[0]-px)+abs(i[1]-py)
                    judge+=1
                elif base==i[2]+abs(i[0]-px)+abs(i[1]-py):
                    judge+=1
            else:
                if max(base-abs(i[0]-px)-abs(i[1]-py),0)==0:
                    judge+=1

        if judge==N:
            print(px,py,base)
            break

Submission status: Accepted

Solution code:

n = int(input())

data = [list(map(int, input().split())) for _ in range(n)]
result = [0] * n
flag = 1

for i in range(n):
    if data[i][2] != 0:
        start = i
        break
for i in range(100 + 1):
    for j in range(100 + 1):
        flag = 1
        h = data[start][2] + abs(data[start][0] - i) + abs(data[start][1] - j)
        for k in range(n):
            if data[k][2] != max(h - abs(data[k][0] - i) - abs(data[k][1] - j), 0):
                flag = 0
                break
        if flag == 1:
            print("{0} {1} {2}".format(i, j, h))
            exit()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    x=[0]*N
    y=[0]*N
    h=[0]*N
    for i in range(N):
        a,b,c=map(int,readline().split())
        x[i]=a
        y[i]=b
        h[i]=c

    ok=False
    for Cx in range(101):
        for Cy in range(101):
            for i in range(N):
                if h[i]==0:
                    continue
                else:
                    H=h[i]+abs(x[i]-Cx)+abs(y[i]-Cy)
                    break
            for i in range(N):
                if h[i]!=max(H-abs(x[i]-Cx)-abs(y[i]-Cy),0):
                    break
            else:
                ok=True

            if ok: break
        if ok: break
    
    print(Cx,Cy,H)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
data = []
for _ in range(N):
    x, y, h = map(int,input().split())
    data.append([h, x, y])
data.sort(reverse=True)
end = False
for x in range(101):
    if end:
        break
    for y in range(101):
        if end:
            break
        hi, xi, yi = data[0]
        H = hi + abs(x - xi) + abs(y - yi)
        for i in range(1, N):
            hi, xi, yi = data[i]
            if max(H - abs(x - xi) - abs(y - yi), 0) != hi:
                break
            if i == N - 1:
                print(x, y, H)
                end = True
                break

Submission status: Accepted

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

# h != 0であるデータを取得
for x, y, h in XYH:
    if h != 0:
        x_, y_, h_ = x, y, h
        break

for cx in range(0, 101):
    for cy in range(0, 101):

        H = abs(x_ - cx) + abs(y_ - cy) + h_

        if all([max(H - abs(x - cx) - abs(y - cy), 0) == h for x, y, h in XYH]):
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
n = int(input())
p = [list(map(int, input().split())) for _ 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)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n = int(input())
x,y,h = [0]*n , [0]*n , [0]*n
q = 0
ze = 0

for i in range(n):
    x[i] ,y[i] ,h[i] = map(int,input().split())
    
ss = Counter(h)
if ss[0] >= n-1:
    ze = 1

for xx in range(101):
    for yy in range(101):
        fl = 1
        a = []
        for i in range(n):
            if h[i] != 0 or ze == 1:
                temp = abs(x[i]-xx) + abs(y[i]-yy) + h[i]
                a.append(temp)
                le = len(a)
                
                if le > 1:
                    if a[le-1] != a[le-2]:
                        fl = 0
                        
        if fl == 1:
            print(xx,yy,max(a))
            sys.exit()

Submission status: Accepted

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

def to_getH(cx,cy):
    for x, y, h in data:
        if h > 0: #h=0だと式が立てられない
            return abs(x - cx) + abs(y - cy) + h
def to_checkH(cx,cy,H):
    for x, y, h in data:
        if h != max(H - abs(x - cx) - abs(y - cy), 0):
            return False
    return True

for cx in range(101):
    for cy in range(101):
        H = to_getH(cx, cy)
        if to_checkH(cx, cy, H):
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    XYH.sort(key=lambda i: i[2], reverse=True)

    for cx in range(101):
        for cy in range(101):
            x, y, h = XYH[0]
            ch = h + abs(cy - y) + abs(cx - x)

            if all([h == max(ch - abs(cy - y) - abs(cx - x), 0) for x, y, h in XYH[1:]]):
                print(cx, cy, ch)
                exit()

    print(XYH)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def set_height(i,x,y):
	ans = z[i][2] + abs(z[i][0] - x) + abs(z[i][1] - y)
	return ans


answer = 0
for j in range(0,101):
	for k in range(0,101):
		flag = 1
		for l in range(0,n):
			if z[l][2] != 0:
				answer = set_height(l,j,k)
				break

		for l in range(0,n):
			if z[l][2] == 0:
				if answer > set_height(l,j,k):	
					flag = 0
					break
			else:
				if answer != set_height(l,j,k):
					flag = 0
					break
		if flag == 1 and answer > 0 :
			test = map(str,(j,k,answer))
			print(" ".join(test))

Submission status: Accepted

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

marker = [0]*101
for Cx in range(101):
  marker[Cx] = [True]*101
  for Cy in range(101):
    h = -1
    for i in range(N):
      X,Y,H = query[i]
      if H==0:
        if h > abs(Cx-X)+abs(Cy-Y):
          marker[Cx][Cy] = False
          break
      else:
        a = H+abs(Cx-X)+abs(Cy-Y)
        if h == -1:
          h = a
        elif h != a:
          marker[Cx][Cy] = False
          break
    if marker[Cx][Cy] == True:
      ans = [Cx,Cy,h]
      print(*ans)
      exit()

Submission status: Accepted

Solution code:
N = int(input())
XYH = [[int(i) for i in input().split()] for _ in range(N)]

XYH.sort(key = lambda x:-x[2])

X0,Y0,H0 = XYH[0]

if N == 1:
    print(X0,Y0,H0)
    exit()

for Cx in range(101):
    for Cy in range(101):
        H = H0 + abs(X0 - Cx) + abs(Y0 - Cy)
        flag = True
        for X,Y,h in XYH[1:]:
            if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                continue
            flag = False
        if flag:
            print(Cx,Cy,H)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
data = [[int(i) for i in input().split()] for _ in range(n)]
for d in data:
    if d[2] > 0:
        sample = d
        break

for cx, cy in product(range(101), repeat=2):
    ch = sample[2] + abs(sample[0]-cx) + abs(sample[1]-cy)
    for x, y, h in data:
        val = h + abs(x-cx) + abs(y-cy)
        if h != max(ch - abs(x-cx) - abs(y-cy), 0):
            break
    else:
        print(cx, cy, ch)
        break

Submission status: Accepted

Solution code:
import itertools
n = int(input())
query = []
for _ in range(n):
    x,y,h = map(int,input().split())
    if h != 0:
        query.append((x,y,h))
tx = query[0][0]
ty = query[0][1]
th = query[0][2]
if len(query) == 1:
    print(tx,ty,th)
    exit()
query.pop(0)
c = [i for i in range(101)]
cc = list(itertools.product(c, repeat=2))
for X,Y in cc:
    H = th + abs(tx-X) + abs(ty-Y)
    Flag = True
    for x,y,h in query:
        if max(H - abs(x-X) - abs(y-Y),0) != h:
            Flag = False
            break
    if Flag:
        print(X,Y,H)
        exit()

Submission status: Accepted

Solution code:
N = int(input())
info = [list(map(int,input().split())) for i in range(N)]

for cx in range(101):
    for cy in range(101):
        H_upper = info[0][2]+abs(info[0][0]-cx)+abs(info[0][1]-cy)
        H_lower = info[0][2]+abs(info[0][0]-cx)+abs(info[0][1]-cy) if info[0][2] != 0 else 0
        for i in range(1,N):
            H_upper = min(H_upper,info[i][2]+abs(info[i][0]-cx)+abs(info[i][1]-cy))
            H_lower = max(H_lower,info[i][2]+abs(info[i][0]-cx)+abs(info[i][1]-cy) if info[i][2] != 0 else 0)
        if H_upper == H_lower and 0 < H_lower:
            print(cx,cy,H_upper)
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
N = int(input())
xyh0 = []
xyh1 = []
for i in range(N):
  x, y, h = map(int, input().split())
  if h:
    xyh1.append([x, y, h])
  else:
    xyh0.append([x, y, h])

cands = []
for cx in range(101):
  for cy in range(101):
    H = -1
    for x, y, h in xyh1:
      _h = h + abs(x-cx) + abs(y-cy)
      if H < 0:
        H = _h
      else:
        if H != _h:
          break
    else:
      cands.append([cx, cy, H])

if cands:
  for cx, cy, H in cands:
    for x, y, h in xyh0:
      if H > abs(x-cx) + abs(y-cy):
        break
    else:
      print(cx, cy, H)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())

    N = II()
    info = []
    for _ in range(N):
        xi, yi, hi = LMIIS()
        if hi != 0:
            xt, yt, ht = xi, yi, hi
        info.append((xi, yi, hi))

    for Cy in range(101):
        for Cx in range(101):
            H = ht + abs(xt - Cx) + abs(yt - Cy)
            found = True
            for xi, yi, hi in info:
                tmp_h = max(H - abs(Cy-yi) - abs(Cx-xi), 0)
                if tmp_h != hi:
                    found = False
                    break
            if found:
                print('{} {} {}'.format(Cx,Cy,H))
                return



if __name__ == '__main__':
    main()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            x, y, h = xyh[k]
            if h:
                H = h + abs(x - cx) + abs(y - cy)
                break

        ans = True
        for k in range(n):
            x, y, h = xyh[k]
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                ans = False
                break
        if ans:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
INF=10**20
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
xyh=sorted(xyh,key=lambda xyh:xyh[2],reverse=True)
for i in range(101):
    for j in range(101):
        res=-INF
        T=True
        for k in range(N):
            tmp=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j)
            if(xyh[k][2]>0):
                if(res==-INF):
                    res=tmp
                elif(res!=tmp):
                    T=not T
                    break
            elif(xyh[k][2]==0):
                if(tmp<res):
                    T=not T
                    break
        if T:
            print(i,j,res)
            exit()

Submission status: Accepted

Solution code:


def read_input():
    n = int(input())
    conds = []
    for _ in range(n):
        x, y, h = map(int, input().split())
        conds.append(((x, y), h))

    return n, conds


def manhattan(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


def satisfy(cond, center):
    c, ch = center
    p, h = cond
    return ch == h + manhattan(p, c)


def zero_satisfy(cond, center):
    c, ch = center
    p, h = cond
    return ch <= manhattan(p, c)


def submit():
    n, conds = read_input()    

    if n == 1:
        p, h = conds[0]
        print("{} {} {}".format(p[0], p[1], h))
        return

    plus_conds = [c for c in conds if c[1] > 0]
    zero_conds = [c for c in conds if c[1] == 0]
    st = plus_conds[0]

    center_cands = []
    for i in range(101):
        for j in range(101):
            t = (i, j)
            th = st[1] + manhattan(st[0], t) # 仮にtがpより高い位置の頂点だとする
            center_cands.append((t, th))
    
    # 各条件について満たすか否かを判定していく
    for cond in plus_conds[1:]:
        center_cands = [c for c in center_cands if satisfy(cond, c)]

    # h=0の条件について、有効かどうか判定していく
    for cond in zero_conds:
        center_cands = [c for c in center_cands if zero_satisfy(cond, c)]

    # 全条件を満たすポイントは1つのはず
    center, h = center_cands[0]
    print("{} {} {}".format(center[0], center[1], h))
            

if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
for i in range(N) :
    p, q, r = map(int,input().split())
    x.append(p)
    y.append(q)
    h.append(r)

for Cx in range(101) :
    for Cy in range(101) :
        for i in range(N) :
            if h[i] :
                H = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy)
                break
        ans = True
        for i in range(N) :
            if h[i] != max(H - abs(x[i] - Cx) - abs(y[i] - Cy), 0) :
                ans = False
        if ans :
            print(Cx, Cy, H)

Submission status: Accepted

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

def check(x,y):

    count = 0
    while l[count][2] == 0:
        count += 1
    h = l[count][2] + abs(x-l[count][0])+abs(y-l[count][1])

    for i,j,k in l[count:]:
        if k != max(h-abs(x-i)-abs(y-j),0):
            return False

    return x,y,h

for i in range(101):
    for j in range(101):
        if check(i,j):
            print(*check(i,j))

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for cx in range(0,101):
  for cy in range(0,101):
    x0,y0,h0=xyh[0]
    H=h0+abs(x0-cx)+abs(y0-cy)
    if H==0:
      continue
    flag=True
    for x,y,h in xyh:
      if h!=max(H-abs(x-cx)-abs(y-cy),0):
        flag=False
    if flag:
      print(cx,cy,H)
      exit()

Submission status: Accepted

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


for i in range(N):
    if xyh[i][2] > 0:
        xx, yy, hh = xyh[i][0], xyh[i][1], xyh[i][2]
        break

for cx in range(101):
    for cy in range(101):
        H = hh + abs(cx-xx) + abs(cy-yy)
        count = 0
        for i in range(N):
            x = xyh[i][0]
            y = xyh[i][1]
            h = xyh[i][2]
            if max(H - abs(x - cx) - abs(y - cy), 0) == h:
                count += 1
        if count == N:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    XYH = [[int(e) for e in input().split()] for i in range(n)]

    for xi in range(101):
        for yi in range(101):
            top = 1
            for x, y, h in XYH:
                if h > 0:
                    top = h + abs(xi - x) + abs(yi - y)
                    break

            topf = True
            for x, y, h in XYH:
                if (h == 0 and top > abs(xi - x) + abs(yi - y)) \
                        or (h > 0 and top != h + abs(xi - x) + abs(yi - y)):
                    topf = False
                    break

            if(topf):
                print(xi, yi, top)
                exit()

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
L = [list(map(int,input().split())) for k in range(N)]
m = 0
for e in L:
    m = max(m,e[2])

def check(x,y,h):
    for e in L:
        if e[2] != max(h-abs(e[0]-x)-abs(e[1]-y),0):
            return False
    return True

for x in range(101):
    for y in range(101):
        for h in range(m,m+101):
            if check(x,y,h) == True:
                print(x,y,h)
                exit(0)

Submission status: Accepted

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
xyh=sorted(xyh,reverse=True,key=lambda x:x[2])
#print(xyh)
for cx in range(0,101):
    for cy in range(0,101):
        H = xyh[0][2] + abs(xyh[0][0] - cx) + abs(xyh[0][1]-cy)
        for x,y,h in xyh:
            if h!= max(H - abs(x - cx) - abs(y - cy),0):
                break

        else:
            if H>=1:
                print(cx,cy,H)
                exit()

Submission status: Accepted

Solution code:
N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))

for i in range(N):
    if p[i][2]:
        tmp = i
        break

for Cx in range(101):
    for Cy in range(101):
        H = p[tmp][2] + abs(Cx-p[tmp][0]) + abs(Cy-p[tmp][1])
        flag = True
        for x,y,h in p:
            if h != max(H -abs(Cx-x) - abs(Cy-y), 0):
                flag = False
                break
        if flag:
            print(Cx,Cy,H)

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    xyh = [tuple(map(int, input().split())) for _ in range(N)]
    xyh.sort(reverse=True, key=lambda x:x[2])

    def check(cx, cy):
        def dist(x, y): return abs(x-cx) + abs(y-cy)
        tmp = 0
        for x, y, h in xyh:
            d = dist(x,y)
            if h == 0:
                if tmp > d: return -1
            else:
                if tmp != 0 and tmp != h+d: return -1
                tmp = h+d
        return tmp
    
    for x in range(101):
        for y in range(101):
            H = check(x,y)
            if H >= 0:
                print('{} {} {}'.format(x,y,H))
                return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

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

for i in range(0, 101):
    for j in range(0, 101):
        temp = []
        border = float('inf')
        for k in range(n):
            x = L[k][0]
            y = L[k][1]
            h = L[k][2]
            if h > 0:
                H = abs(i-x)+abs(j-y)+h
                temp.append(H)
            else:
                border = min(border, abs(i-x)+abs(j-y))
        temp = list(set(temp))
        if len(temp) == 1 and temp[0] <= border:
            ans = [i, j, H]
print(*ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    XYH = [[int(i) for i in input().split()] for j in range(N)]
    XYH.sort(reverse=True, key=lambda p: p[2])

    for cy in range(101):
        for cx in range(101):
            ch = XYH[0][2] + abs(XYH[0][0] - cx) + abs(XYH[0][1] - cy)
            for x, y, h in XYH[1:]:
                if h != max(ch - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                if ch != 0:
                    return print(cx, cy, ch)
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
XYH = (tuple(map(int, input().split())) for _ in range(N))
XYH = np.array([input().split() for _ in range(N)], dtype=int)
X, Y, H = XYH.T

z = np.argmax(H)
x, y, h = XYH[z]

for Cx in range(0, 101):
    for Cy in range(0, 101):
        estH = h + abs(Cx - x) + abs(Cy - y)
        tmpH = np.maximum(0, estH - np.abs(X - Cx) - np.abs(Y - Cy))
        if np.all(H == tmpH):
            print(Cx, Cy, estH)
            exit()

Submission status: Accepted

Solution code:
n=int(input())
X=[]
Y=[]
H=[]
hi=int(0)
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h!=0:
        hi=i
for x in range(101):
    for y in range(101):
        now=H[hi]+abs(X[hi]-x)+abs(Y[hi]-y)
        ans=1
        for i in range(n):
            nowi=now-abs(X[i]-x)-abs(Y[i]-y)
            nowi=max([nowi,0])
            if H[i]!=nowi:
                ans=0
        if ans==1:
            print("{} {} {}".format(x,y,now))
            exit()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    P = [[int(p) for p in input().split()] for _ in range(N)]
    Ans = [None, None, None]
    for x in range(101):
        for y in range(101):
            hight = 10 ** 20
            fixed = False
            for cx, cy, ch in P:
                if ch == 0: 
                    tempH = abs(x - cx) + abs(y - cy)
                    if not fixed: hight = min(hight, tempH)
                    else:
                        if tempH < hight: break
                else: 
                    tempH = ch + abs(x - cx) + abs(y - cy)
                    if not fixed: 
                        if hight < tempH: break
                        else: 
                            hight = tempH
                            fixed = True
                    else:
                        if hight != tempH: break
            else:
                Ans = [x, y, hight]
                break
        if Ans[0] != None: break

    print(" ".join(map(str, Ans)))
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda a: -a[2])
for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        H = h+abs(cx-x)+abs(cy-y)
        for i in range(1, N):
            x, y, h = xyh[i]
            if max(H-abs(cx-x)-abs(cy-y), 0) != h:
                break
        else:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
from operator import itemgetter


def main():
    n = int(input())
    data = sorted([[int(i) for i in input().split()] for _ in range(n)], key=itemgetter(2), reverse=True)
    if data[0][2] == 1 and (n == 1 or data[1][2] == 0):
        print(*data[0])
        return
    test, *valid = data

    for x in range(101):
        for y in range(101):
            h = abs(test[0] - x) + abs(test[1] - y) + test[2]
            for v in valid:
                if max(h - abs(x - v[0]) - abs(y - v[1]), 0) != v[2]:
                    break
            else:
                print(x, y, h)
                return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  xs, ys, hs = [], [], []
  for _ in range(n):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)
    
  for i in range(n):
    if hs[i] > 0:
      xx, yy, hh = xs[i], ys[i], hs[i]
      break
    
  for cx in range(0, 101):
    for cy in range(0, 101):
      H = hh + abs(cx - xx) + abs(cy - yy)
      flag = True
      for x, y, h in zip(xs, ys, hs):
        if not max(H-abs(x - cx)-abs(y-cy), 0) == h:
          flag = False
          break
      if flag:
        print(cx, cy, H)
        return

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n=int(input())
  xyh=[list(map(int,input().split())) for _ in [0]*n]
  xx,yy,hh=sorted(xyh,key=lambda x:x[2])[-1]
  for cx in range(101):
    for cy in range(101):
      H=hh+abs(xx-cx)+abs(yy-cy)
      for x,y,h in xyh:
        if max(H-abs(x-cx)-abs(y-cy),0)!=h:
          break
      else:
        print(cx,cy,H) 
        exit()
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
xyh = []
for i in range(N):
    xyh.append([int(i) for i in input().split()])

#サンプルを用意
for x,y,h in xyh:
    if h!=0:
        xs,ys,hs=x,y,h


for cx in range(100+1):
    for cy in range(100+1):
        guessed_H = hs+abs(xs-cx)+abs(ys-cy)
        if all([max(0,guessed_H-abs(cx-x)-abs(cy-y))==h for x,y,h in xyh]):
            print(cx,cy,guessed_H)

Submission status: Accepted

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

for i in range(N):
    if xyh[i][2] != 0:
        xs, ys, hs = xyh[i]

for xt in range(101):
    for yt in range(101):
        ht = hs + abs(xt - xs) + abs(yt - ys)
        if all([xyh[i][2] == max(0, ht - abs(xt-xyh[i][0]) - abs(yt-xyh[i][1])) for i in range(N)]):
            xa, ya, ha = xt, yt, ht
            
print(xa,ya,ha)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split())) for i in range(N)]
for i in range(N):
    if xyh[i][2] != 0:
        xs, ys, hs = xyh[i]
for xt in range(101):
    for yt in range(101):
        ht = hs + abs(xt - xs) + abs(yt - ys)
        if all([xyh[i][2] == max(0, ht - abs(xt-xyh[i][0]) - abs(yt-xyh[i][1])) for i in range(N)]):
            xa, ya, ha = xt, yt, ht
print(xa,ya,ha)

Submission status: Accepted

Solution code:
n = int(input())
xyh = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: -x[2])
for x in range(101):
    for y in range(101):
        h=xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
        for X,Y,H in xyh[1:]:
            if H != max(h-abs(x-X)-abs(y-Y),0):
                break
        else:
            print(x,y,h)
            exit()

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        h=xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
        flag = True
        for X,Y,H in xyh[1:]:
            if H != max(h-abs(x-X)-abs(y-Y),0):
                flag = False
                break
        if flag:
            print(x,y,h)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
X = []
Y = []
hh = []
vec = list()
G = (-1,-1,-1)

for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    hh.append(h)
    # 高さが1以上の三組を一つ取る(この場合, hi = H - |Xi - Cx| - |Yi - Cy|が成立する)
    if h >= 1:
        G = (x, y, h)

for i in range(0,101):
    for j in range(0,101):
        # 最初にHを固定する
        H = G[2] + abs(G[0] - i) + abs(G[1] - j)
        H = max(H, 0)
        flag = True
        for k in range(N):
            key = H - abs(X[k] - i) - abs(Y[k] - j)
            key = max(key, 0)
            if key != hh[k]:
                flag = False
        # 全てのkについてHが成立するとき, append
        if flag:
            vec.append((i,j,H))

if len(vec) == 1:
    print(vec[0][0], vec[0][1], vec[0][2])

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        H = h_+abs(x_ - cx) + abs(y_ - cy)
        for x, y, h in xyh:
            if max(H - abs(x-cx)-abs(y-cy), 0) != h:
                break
        else:
            print(cx, cy, H)
            exit()

Submission status: Accepted

Solution code:
n = int(input())

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

x_, y_, h_ = sorted(dots, key=lambda x: x[2], reverse=True)[1]

for cx in range(101):
    for cy in range(101):
        H = h_+abs(x_ - cx) + abs(y_ - cy)

        ans = []
        for x, y, h in dots:
            if max(H - abs(x-cx)-abs(y-cy), 0) == h:
                ans.append((cx, cy, H))

        if len(ans) == n:
            print(*ans[0])
            exit()