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 sys
input = sys.stdin.readline

N = int(input())
cx = [i for i in range(101)]
cy = [i for i in range(101)]
x = []
y = []
h = []
flag = True
index = 0
for i in range(N):
    xi,yi,hi = map(int,input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)
    if hi != 0 and flag:
        index = i
answer = []
for cx in range(101):
    for cy in range(101):
        H = h[index]+abs(x[index]-cx)+abs(y[index]-cy)
        for i in range(N):
            if h[i] == max(H-abs(x[i]-cx)-abs(y[i]-cy),0):
                if i == N-1:
                    answer = [cx,cy,H]
                continue
            else:
                break

print(str(answer[0])+' '+str(answer[1])+' '+str(answer[2]))

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []

for i in range(n):
	xtemp, ytemp, htemp = map(int, input().split())
	x.append(xtemp)
	y.append(ytemp)
	h.append(htemp)
H = 1000000000

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
X,Y,H=[],[],[]
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h>0:
        k=i
for x in range(101):
    for y in range(101):
        h=H[k]+abs(X[k]-x)+abs(Y[k]-y)
        if all([max(h-abs(xi-x)-abs(yi-y),0)==hi for xi,yi,hi in zip(X,Y,H)]):
            print(x,y,h)
            exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())
X, Y, H = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for x in range(101):
    for y in range(101):
        hc = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] > 0}
        h0 = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] == 0}
        if len(hc) == 1:
            if (len(h0) > 0 and min(h0) >= list(hc)[0]) or len(h0) == 0:
                print(x, y, list(hc)[0])
                break

Submission status: Accepted

Solution code:
N=int(input())

data=[list(map(int,input().split())) for _ in range(N)]
hmax=max(data,key= lambda x:x[2])[2]

def check(x,y,h):
    flag=True
    for d in data:
        flag&=(d[2]==max(h-abs(d[0]-x)-abs(d[1]-y),0))
        if not flag:
            break
    return flag

for cx in range(101):
    for cy in range(101):
        for ch in range(hmax,hmax+202):
            if check(cx,cy,ch):
                print(cx,cy,ch)

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
for j in range(N):
  if L[j][2] != 0:
    karix = L[j][0]
    kariy = L[j][1]
    karih = L[j][2]
    break
for p in range(0,101):
  for q in range(0,101):
    cnt = 0
    kouhoH = karih+abs(karix-p)+abs(kariy-q)
    for r in range(N):
      if  L[r][2] == max(kouhoH-abs(L[r][0]-p)-abs(L[r][1]-q),0):
        cnt += 1
    if cnt == N:
      print(p,q,kouhoH)
      exit()

Submission status: Accepted

Solution code:
from itertools import product


def solve(string):
    n, *xyh = map(int, string.split())
    xyh = sorted([(x, y, h) for x, y, h in zip(xyh[::3], xyh[1::3], xyh[2::3])],
                 key=lambda x: x[-1], reverse=True)
    for i, j in product(range(101), range(101)):
        h = abs(xyh[0][0] - i) + abs(xyh[0][1] - j) + xyh[0][2]
        check = [_h == max(h - abs(_x - i) - abs(_y - j), 0) for _x, _y, _h in xyh[1:]]
        if all(check):
            return "{} {} {}".format(i, j, h)


if __name__ == '__main__':
    n = int(input())
    print(solve("{}\n".format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
import sys
n = int(input())
x,y,h = [],[],[]
for i in range(n):
  xi,yi,hi = map(int, input().split())
  x.append(xi)
  y.append(yi)
  h.append(hi)
  if hi>0:
    num = i
  
for cx in range(0,101):
  for cy in range(0,101):
    H = h[num]+abs(x[num]-cx)+abs(y[num]-cy)
    if all([max(H-abs(xi-cx)-abs(yi-cy),0)==hi for xi,yi,hi in zip(x,y,h)]):
      print(cx,cy,H)
      sys.exit()

Submission status: Accepted

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

flag = False
ans = [0, 0, 0]
for i in range(101):
  for j in range(101):
    for k in range(N):
      Xt, Yt, Ht = L[k][0], L[k][1], L[k][2]
      if Ht > 0:
        break
    H = Ht + abs(Xt - i) + abs(Yt - j)
    result = []
    for k in range(N):
      l = L[k]
      if l[2] == max(H - abs(i - l[0]) - abs(j - l[1]), 0):
        result.append(True)
      else:
        result.append(False)
    if result.count(True) == N:
      ans[0], ans[1], ans[2] = i, j, H
      flag = True
      break
  if flag:
    break

print("{} {} {}".format(ans[0], ans[1], ans[2]))

Submission status: Accepted

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

for cxi in range(101):
    for cyi in range(101):
        for k in range(N):
            if params[k][2] > 0:
                hight = params[k][2] + abs(params[k][0] - cxi) + abs(params[k][1] - cyi)

        for k in range(N):
            if params[k][2] != max((hight - abs(params[k][0] - cxi) - abs(params[k][1] - cyi)), 0):
                break
        
        else:
            print(cxi, cyi, hight)

Submission status: Accepted

Solution code:
N = int(input())
x, y, h = [[0]*N, [0]*N, [0]*N]
for n in range(N):
  x[n], y[n], h[n] = map(int, input().split())
  if h[n] > 0:
    hi = n

def g(xx, yy, height):
  for n in range(N):
    if max(height-abs(xx-x[n])-abs(yy-y[n]), 0) != h[n]:
      return False
  return True

def f():
  for xx in range(101):
    for yy in range(101):
      height = abs(xx-x[hi])+abs(yy-y[hi])+h[hi]
      if g(xx, yy, height) is True:
        return [xx, yy, height]
print(*f())

Submission status: Accepted

Solution code:
n=int(input())
s=[]
for i in range(n):
  x,y,h=map(int,input().split())
  s.append([x,y,h])
s=sorted(s,key=lambda x:x[2],reverse=True)
x0,y0,h0=s[0] #少なくとも一つはhi>0だからhの最大のものを取る
for x in range(101):
  for y in range(101):
    H=h0+abs(x0-x)+abs(y0-y) #h0=H-abs(x0-x)+abs(y0-y)の式変形(hiが0以上の前提)
    for xi,yi,hi in s:
      if hi!=max(0,H-abs(xi-x)-abs(yi-y)):
        break
    else: #for文の下のelseは(breakすることなしに)for文を抜けることができたら反映
      print(x,y,H)
      exit()

Submission status: Accepted

Solution code:
n=int(input())
X=[]
Y=[]
H=[]
for i in range(n):
  x,y,h=map(int,input().split())
  X.append(x)
  Y.append(y)
  H.append(h)
for x in range(101):
  for y in range(101):
    for i in range(n):
      if H[i]>0:
        h=H[i]+abs(X[i]-x)+abs(Y[i]-y)
    for i in range(n):
      if H[i]!=max(0,h-abs(X[i]-x)-abs(Y[i]-y)):
        break
    else: #for文の下のelseは(breakすることなしに)for文を抜けることができたら反映
      print(x,y,h)
      exit()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
"""
x, y, h = np.array([list(map(int, input().split())) for i in range(N)]).T
"""
x = [0 for i in range(N)]
y = [0 for i in range(N)]
h = [0 for i in range(N)]
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())

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

print("{} {} {}".format(Cx, Cy, H))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())

x, y, h = np.array([list(map(int, input().split())) for i in range(N)]).T
"""
x = [0 for i in range(N)]
y = [0 for i in range(N)]
h = [0 for i in range(N)]
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())
"""
H = 0
Cx = 0
Cy = 0
Flag = True
for i in range(101):
    for j in range(101):
        Flag = True
        for k in range(N):
            if h[k] != 0:
                H = h[k] + abs(i - x[k]) + abs(j - y[k])
                break
        for k in range(N):
            if h[k] != max(H - abs(i - x[k]) - abs(j - y[k]), 0):
                Flag = False
                break
        
        if Flag:
            Cx, Cy = i, j
            break
    if Flag:
        break

print("{} {} {}".format(Cx, Cy, H))

Submission status: Accepted

Solution code:
#abc112c

n=int(raw_input())
l=[]
for i in xrange(n):
 x,y,h=map(int,raw_input().split())
 l.append([x,y,h])
for cx in xrange(101):
 for cy in xrange(101):
  for k in xrange(n):
   if l[k][2]>0:
    h=abs(l[k][0]-cx)+abs(l[k][1]-cy)+l[k][2]
    break
  flag=False
  for k in xrange(n):
   if l[k][2]!=max(h-abs(l[k][0]-cx)-abs(l[k][1]-cy),0):
    flag=True
    break
  if flag==False:
   print cx,cy,h

Submission status: Accepted

Solution code:
X = []
Y = []
L = []
N = int(input())
for i in range(N):
   x, y, l = map(int, input().split())
   X.append(x)
   Y.append(y)
   L.append(l)
maxL = max(L)
for cx in range(0, 101):
    for cy in range(0, 101):
        for h in range(maxL, maxL+101):
            flag = True
            for i, l in enumerate(L):
                if l != max(h - abs(X[i] - cx) - abs(Y[i] -cy), 0):
                    flag = False
                    break
            if flag:
                print(cx, cy, h)
                exit()

Submission status: Accepted

Solution code:
N = int(input())

position_list = []
for _ in range(N):
    asdf = list(map(int, input().split(' ')))
    position_list.append(asdf)
    if asdf[2] >= 1:
        base_position = asdf

def check_position_diff(position1, position2):
    x = position1[0] - position2[0]
    y = position1[1] - position2[1]
    return x, y

for x in range(102):
    for y in range(102):
        diff_x, diff_y = check_position_diff((x,y), (base_position[0], base_position[1]))
        h = max(abs(diff_x) + abs(diff_y) + base_position[2], 0)
        collect = []
        for position in position_list:
            diff_x, diff_y = check_position_diff((x,y), (position[0], position[1]))
            hx = max(h - abs(diff_x) - abs(diff_y),0)
            collect.append(position[2]==hx)
        if all(collect):
            print(x, y, h)
            exit()
        collect=[]

Submission status: Accepted

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

for j in range(101):
  for k in range(101):
    height_summit = h+abs(x-j)+abs(y-k)
    flag=1
    for point in l:
      if point[2] == max(height_summit-abs(point[0]-j)-abs(point[1]-k), 0):
        pass
      else:
        flag=0
        break
    if flag:
      print(j,k,height_summit)
      quit()

Submission status: Accepted

Solution code:
N = int(input())
s = []
for _ in [0]*N:
    x, y, h = map(int, input().split())
    s.append([x, y, h])

s.sort(key=lambda x:x[2], reverse=True)
ansH = 0
x0, y0, h0 = s[0]
for cx in range(0, 101):
    for cy in range(0, 101):
        H = h0 + abs(x0 - cx) + abs(y0 - cy)
        for x, y, h in s:
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                continue
            else:
                break
        else:
            print(cx, cy, H)

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        height = set(hi + abs(xi-cx) + abs(yi-cy) for xi, yi, hi in xyh if hi > 0)
        if len(height) == 1:
            H = max(height)
            if all(set(hi==max(H - abs(xi-cx) - abs(yi-cy), 0) for xi, yi, hi in xyh if hi == 0)):
                print(cx, cy, H)
                exit()

Submission status: Accepted

Solution code:
n=int(input())
xyh=[]
for i in range(n):
    xyh.append(list(map(int,input().split())))
x0=xyh[0][0]
y0=xyh[0][1]
h0=xyh[0][2]
count=0
while h0==0:
    count+=1
    x0=xyh[count][0]
    y0=xyh[count][1]
    h0=xyh[count][2]
for x in range(101):
    for y in range(101):
        h=h0+abs(x-x0)+abs(y-y0)
        for i in range(n):
            if max(0,h-abs(x-xyh[i][0])-abs(y-xyh[i][1]))!=xyh[i][2]:
                break
            if i==n-1:
                print(x,y,h)
                quit()

Submission status: Accepted

Solution code:
from collections import namedtuple

def main():
    Place = namedtuple('Place', ('x', 'y', 'h'))

    N = int(input())

    place = [None for _ in range(N)]
    for i in range(N):
        x, y, h = map(int,input().split())
        place[i] = Place(x,y,h)

    place = list(filter(lambda t:t.h != 0, place))
    place_len = len(place)
    if place_len == 1:
        print(place[0].x, place[0].y, place[0].h)
        return

    for cy in range(101):
        for cx in range(101):
            sc0 = place[0].h + abs(cx - place[0].x) + abs(cy - place[0].y)
            for i in range(1, place_len):
                sci = place[i].h + abs(cx - place[i].x) + abs(cy - place[i].y)
                if sc0 != sci:
                    break
            else:
                print(cx, cy, sc0)
                return

main()

Submission status: Accepted

Solution code:
#最低でも1つはピラミッド内の座標がないと解けない？

N = int(input())
#これが唯一の事実データ
src = [tuple(map(int,input().split())) for i in range(N)]
 
INF = float('inf')
#ここ以降でかかれてあるcx,cyはあくまで頂上であると仮定しているだけで条件と合わない場合に不適切な座標となる。
for cx in range(0,101):
    for cy in range(0,101):
        tmph = None
        maxh = INF
        for x,y,h in src:
            if h > 0:
                tmp = h + abs(x-cx) + abs(y-cy)
                if tmph is None:
                    tmph = tmp
                else:
                    #ここが等しくないとピラミッドの高さの公式に矛盾する
                    if tmp != tmph:
                        break
                if tmph > maxh:
                    break
            else:
                #ここでmaxhがtmphよりも小さくなってしまった場合、hは0だから頂点からのxとyの差の和が最低でもtmphはなければならないのに、それを下回っているため
                #データx,yは絶対的な値なのでcx,cyが間違っていることになる。それを判定するのが上のtmph > maxh の時
                maxh = min(maxh, abs(x-cx) + abs(y-cy))
        else:
            for x,y,h in src:
                if max(tmph - abs(x-cx) - abs(y-cy), 0) != h:
                    break
            else:
                print(cx,cy,tmph)
                exit()

Submission status: Accepted

Solution code:
N = int(input())
x_list=[]
y_list=[]
h_list=[]
hantei = 0
count=0
for i in range(N):
    a,b,c=map(int,input().split())
    x_list.append(a)
    y_list.append(b)
    h_list.append(c)
    if c>0: 
        judge_x = a
        judge_y = b
        judge_h = c

for x in range(101):
    for y in range(101):
        H = judge_h + abs(judge_x-x)+abs(judge_y-y)
        for j in range(N):
            if h_list[j] != max(0,H-abs(x-x_list[j])-abs(y-y_list[j])): break
            if j == N-1 : print(x,y,judge_h + abs(x-judge_x) + abs(y-judge_y))

Submission status: Accepted

Solution code:
N = int(input())
 
def calc_h(H, x, y, cx, cy):
    return max(H - abs(x - cx) - abs(y - cy), 0)
 
data_ls = list()
for i in range(N):
    data_ls.append([int(i) for i in input().split()])
xs, ys, hs = zip(*data_ls)
Cx_candidate = list(range(min(xs), max(xs) + 1))
Cy_candidate = list(range(min(ys), max(ys) + 1))
flg = 0
for x in Cx_candidate:
    for y in Cy_candidate:
    	for i in data_ls:
            if i[2] == 0:
                continue
            h = i[2] + abs(i[0] - x) + abs(i[1] - y)
            if h < 1:
            	continue
            else:
            	break
    	for i in data_ls:
            if calc_h(h, i[0], i[1], x, y) == i[2]:
              	flg = 1
              	continue
            else:
              	flg = 0
              	break
    	if flg == 1:
        	break
    if flg == 1:
    	break
print(x, y, h)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    def is_match_to_samples(cx, cy):
        hmax = max(h)
        hmax_idx = h.index(hmax)
        ht = top_height(cx, cy, x[hmax_idx], y[hmax_idx], hmax)
        for xi, yi, hi in zip(x, y, h):
            if hi != height(cx, cy, xi, yi, ht):
                return False, -1
        return True, ht

    import itertools
    for cx, cy in itertools.product(range(101), range(101)):
        is_match, ht = is_match_to_samples(cx, cy)
        if is_match:
            print("{} {} {}".format(cx, cy, ht))
            break
    return

def height(cx, cy, xi, yi, ht):
    return max(0, ht - abs(cx - xi) - abs(cy - yi))

def top_height(cx, cy, xi, yi, hi):
    return hi + abs(cx - xi) + abs(cy - yi)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    h = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    solve(N, x, y, h)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []

for i in range(0, n):
    xi, yi, hi = [int(i) for i in input().split(" ")]
    x.append(xi)
    y.append(yi)
    h.append(hi)

#n = 10
#x = [10, 0, 1, 5, 2, 1, 0, 2, 0, 0]
#y = [10, 0, 0, 6, 0, 1, 2, 2, 8, 1]
#h = [0, 0, 1, 0, 0, 2, 0, 0, 0, 1]

for cx in range(0, 101):
    for cy in range(0, 101):
        hd = -1
        f = False
        for i in range(0, n):
            if h[i] > 0:
                ht = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                if hd == -1 or hd == ht:
                    hd = ht
                else:
                    f = True
                    break
                    
        for i in range(0, n):
            if h[i] == 0:
                if max(hd - abs(x[i] - cx) - abs(y[i] - cy), 0) != 0:
                    f = True
                    break
        
        if not f:
            print(cx, cy, hd)

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        height_set = set(hi + abs(xi-cx) + abs(yi-cy) for xi, yi, hi in zahyo if hi > 0)
        if len(height_set) == 1:
            H = max(height_set)
            if all(set(hi == max(H - abs(xi-cx) - abs(yi-cy), 0) for xi, yi, hi in zahyo if hi == 0)):
                print(cx, cy, max(height_set))
                exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':


N = int(input().rstrip())
xyh = []
itr = 0
for i in range(N):
	a, b, c = map(int, input().rstrip().split())
	itr = max(itr, c)
	xyh.append([a, b, c])

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

for i in range(101):
	for j in range(101):
		for k in range(itr, itr+101):
			if solve(i, j, k):
				print(str(i) + " " + str(j) + " " + str(k))

Submission status: Accepted

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

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

for x in range(101):
    for y in range(101):
        h = L[-1][2] + abs(x-L[-1][0]) + abs(y-L[-1][1])
        for l in L: 
            if l[2] == 0:
                if h - (abs(x-l[0]) + abs(y-l[1])) > 0:
                    flag = 0
                    break
            else:

                if h == l[2] + abs(x-l[0]) + abs(y-l[1]):
                    flag = 1
                
                else:
                    flag = 0
                    break
                
                
        if flag == 1:
            gx = x
            gy = y
            gh = h
            break
                
                    
    if flag == 1:
        break
        
print(gx, gy, gh)

Submission status: Accepted

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

def main():
    for i in range(101):
        for j in range(101):
            H = 0
            for x,y,h in S:
                if h==0:
                    continue
                else:
                    H = h+abs(x-i)+abs(y-j)
                    break
            flg = True
            for x,y,h in S:
                if h != max(0, H-abs(x-i)-abs(y-j)):
                    flg = False
                    break
            if flg:
                print(i, j, H)
                return

main()

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
h = []
for i in range(n):
    a,b,c = map(int, input().split())
    x.append(a)
    y.append(b)
    h.append(c)
    
index = h.index(max(h))
for cx in range(101):
    for cy in range(101):
        H = h[index] + abs(x[index] - cx) + abs(y[index] - cy)
        flag = True
        for i in range(n):
            if h[i] > 0:
                if H != (h[i] + abs(x[i] - cx) + abs(y[i] - cy)):
                    flag = False
            if h[i] == 0:
                if (H -  abs(x[i] - cx) - abs(y[i] - cy)) > 0:
                    flag = False
        if flag:
            print(cx,cy,H)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    xList = []
    yList = []
    hList = []
    for i in range(N):
        x, y, h = list(map(int, input().split()))
        xList.append(x)
        yList.append(y)
        hList.append(h)
        if h > 0:
            x1 = x  
            y1 = y
            h1 = h
    
    for cx in range(100+1):
        for cy in range(100+1):
            H = h1 + abs(x1-cx) + abs (y1-cy)
            for x, y, h in zip(xList, yList, hList):
                if h != max(H-abs(x-cx)-abs(y-cy), 0):
                    break
            else:
                print(cx, cy, H)
                return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#prdさんから参照
#最低でも1つはピラミッド内の座標がないと解けない？

N = int(input())
#これが唯一の事実データ
src = [tuple(map(int,input().split())) for i in range(N)]
 
INF = float('inf')
#ここ以降でかかれてあるcx,cyはあくまで頂上であると仮定しているだけで条件と合わない場合に不適切な座標となる。
for cx in range(0,101):
    for cy in range(0,101):
        tmph = None
        maxh = INF
        for x,y,h in src:
            if h > 0:
                tmp = h + abs(x-cx) + abs(y-cy)
                if tmph is None:
                    tmph = tmp
                else:
                    if tmp != tmph:
                        break
                if tmph > maxh:
                    break
            else:
                #ここでmaxhがtmphよりも小さくなってしまった場合、hは0だから頂点からのxとyの差の和がtmphはなければならないのに、それを下回っているため
                #データx,yは絶対的な値なのでcx,cyが間違っていることになる。それを判定するのが上のtmph > maxh の時となり
                maxh = min(maxh, abs(x-cx) + abs(y-cy))
        else:
            for x,y,h in src:
                if max(tmph - abs(x-cx) - abs(y-cy), 0) != h:
                    break
            else:
                print(cx,cy,tmph)
                exit()

Submission status: Accepted

Solution code:
#模範解答
N = int(input())
#これが唯一の事実データ
src = [tuple(map(int,input().split())) for i in range(N)]
 
INF = float('inf')
#ここ以降でかかれてあるcx,cyはあくまで頂上であると仮定しているだけで条件と合わない場合に不適切な座標となる。
for cx in range(0,101):
    for cy in range(0,101):
        tmph = None
        maxh = INF
        for x,y,h in src:
            if h > 0:
                tmp = h + abs(x-cx) + abs(y-cy)
                if tmph is None:
                    tmph = tmp
                else:
                    if tmp != tmph:
                        break
                if tmph > maxh:
                    break
            else:
                #ここでmaxhがtmphよりも小さくなってしまった場合、hは0だから頂点からのxとyの差の和がtmphはなければならないのに、それを下回っているため
                #データx,yは絶対的な値なのでcx,cyが間違っていることになる。それを判定するのが上のtmph > maxh の時となり
                maxh = min(maxh, abs(x-cx) + abs(y-cy))
                #ピラミッドが高さ１の頂点のみだった場合、h=1のデータが与えられていればいいがh=０しか与えられていない時のため
#                 if maxh == 1:
#                     tmph = 1
        else:
            for x,y,h in src:
                if max(tmph - abs(x-cx) - abs(y-cy), 0) != h:
                    break
            else:
                print(cx,cy,tmph)
                exit()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc112/tasks/abc112_c

N = int(input())

p_l = [list(map(int, input().split())) for _ in range(N)]
p_l.sort(key=lambda x: -x[2])

temp_p = p_l[0]

for x in range(101):  # X
    for y in range(101):  # Y
        # 仮の中心
        h = temp_p[2] + abs(temp_p[1] - y) + abs(temp_p[0] - x)

        if all(max(h - abs(p[1] - y) - abs(p[0] - x), 0) == p[2] for p in p_l[1:]):
            print("{} {} {}".format(x, y, h))
            exit()

Submission status: Accepted

Solution code:
from sys import stdin

N, *xyh = map(int, stdin.read().split())

xyh = list(zip(*[iter(xyh)] * 3))
xyh.sort(key=lambda x: -x[2])

x1, y1, h1 = xyh[0]
for X in range(101):
    for Y in range(101):
        H = h1 + abs(x1-X) + abs(y1-Y)
        if all(max(H-abs(x-X)-abs(y-Y), 0) == h for x, y, h in xyh[1:]):
            print(X, Y, H)
            break

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import product

N, *xyh = map(int, stdin.read().split())

xyh = list(zip(*[iter(xyh)] * 3))
xyh.sort(key=lambda x: -x[2])

x1, y1, h1 = xyh[0]
for X, Y in product(range(101), range(101)):
    H = h1 + abs(x1-X) + abs(y1-Y)
    if all(max(H-abs(x-X)-abs(y-Y), 0) == h for x, y, h in xyh[1:]):
        print(X, Y, H)
        break

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import product

N, *xyh = map(int, stdin.read().split())

xyh = list(zip(*[iter(xyh)] * 3))
xyh.sort(key=lambda x: x[2], reverse=True)

x1, y1, h1 = xyh[0]
for X, Y in product(range(101), range(101)):
    H = h1 + abs(x1-X) + abs(y1-Y)
    if all(max(H-abs(x-X)-abs(y-Y), 0) == h for x, y, h in xyh[1:]):
        print(X, Y, H)
        break

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import product

N, *xyh = map(int, stdin.read().split())

xyh = list(zip(*[iter(xyh)] * 3))
xyh.sort(key=lambda x: x[2], reverse=True)

x1, y1, h1 = xyh[0]
for X, Y in product(range(101), range(101)):
    H = h1 + abs(x1-X) + abs(y1-Y)
    if all([max(H-abs(x-X)-abs(y-Y), 0) == h for x, y, h in xyh[1:]]):
        print(X, Y, H)
        break

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import product

N, *xyh = map(int, stdin.read().split())

xyh = list(zip(*[iter(xyh)] * 3))
xyh = [t for t in xyh if t[2] > 0]
xyh.sort(key=lambda x: x[2], reverse=True)

x1, y1, h1 = xyh[0]
if len(xyh) < 3:
    print(x1, y1, h1)
else:
    for X, Y in product(range(101), range(101)):
        H = h1 + abs(x1-X) + abs(y1-Y)
        if all([max(H-abs(x-X)-abs(y-Y), 0) == h for x, y, h in xyh[1:]]):
            print(X, Y, H)
            break

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
origin = []
modified = []
for i in range(n):
    tx, ty, th = map(int, input().split())
    origin.append([tx, ty, th])
    if th != 0:
        modified.append([tx, ty, th])
origin = np.array(origin).T
modified = np.array(modified).T
for cx in range(0,101):
    for cy in range(0,101):
        tmp = modified[2] + np.abs(modified[0] - cx) + np.abs(modified[1] - cy)
        if np.max(tmp) == np.min(tmp):
            height = np.max(tmp)
            # print("cx = ", cx, "cy = ", cy, "height =", height)
            # print(origin[0])
            # print(origin[1])
            # print(origin[2])
            # print(np.maximum(height - np.abs(origin[0] - cx) - np.abs(origin[1] - cy), np.zeros(origin[0].size)))
            if (origin[2] == np.maximum(height - np.abs(origin[0] - cx) - np.abs(origin[1] - cy), np.zeros(origin[0].size))).all():
                print(cx, cy, height)

Submission status: Accepted

Solution code:
def main() -> None:
    N = int(input())
    pos = [[int(i) for i in input().split()] for _ in range(N)]
    pos = sorted(pos, key=lambda x: x[2], reverse=True)
    x, y, h = pos[0]
    for CX in range(101):
        for CY in range(101):
            H = h + abs(x - CX) + abs(y - CY)
            if all(posh == max(H - abs(posx - CX) - abs(posy - CY), 0) for posx, posy, posh in pos):
                print('{x} {y} {h}'.format(x=CX, y=CY, h=H))
                exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import fabs

def main():
  N = int(input())

  cors = [list(map(int, input().split())) for _ in range(N)]
  cors_sorted = sorted(cors, key = lambda x: x[2], reverse=True)
  top_x, top_y, top_h = cors_sorted[0]

  for C_x in range(101):
    for C_y in range(101):
      H = top_h + fabs(top_x - C_x) + fabs(top_y - C_y)
      if all([h == max(H - fabs(x - C_x) - fabs(y - C_y), 0) for x,y,h in cors_sorted]):
        print(C_x, C_y, int(H))
        return


main()