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

def get_height(h, x, y, cx, cy):
	for i in range(len(h)):
		if h[i] == 0:
			continue
		return h[i] + abs(x[i] - cx) + abs(y[i] - cy)

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

for cx in range(101):
	for cy in range(101):
		height = get_height(h, x, y, cx, cy)
		for i in range(n):
			if h[i] != max(0, height - abs(x[i] - cx) - abs(y[i] - cy)):
				break
		else:
			print(cx, cy, height)
			sys.exit()

Submission status: Accepted

Solution code:
N = int(input())
lx, ly, lh = [], [], []
for i in range(N):
    x, y, h = map(int, input().split())
    lx.append(x)
    ly.append(y)
    lh.append(h)
# すべての座標(i, j)について全探索
for i in range(101):
    for j in range(101):
        k = 0
        while lh[k] == 0:
            k += 1
        H = int(abs(lx[k]-i)) + int(abs(ly[k]-j)) + lh[k]
        b = True
        for k in range(len(lh)):
            if lh[k] != max(H - int(abs(lx[k]-i)) - int(abs(ly[k]-j)), 0):
                b = False
                break
        if b:
            print(i, j, H)

Submission status: Accepted

Solution code:
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
li = []
for i in range(n):
  if lis[i][-1] != 0:li.append(lis[i])
ans = []
for i in range(101):
  for j in range(101):
    H = abs(li[0][0]-i)+abs(li[0][1]-j)+li[0][2]
    key = 0
    for x,y,h in lis:
      if max(0,H- abs(x-i)-abs(y-j)) != h:
        key = 1
    if key == 0:ans.append([i,j,H])
if len(ans) == 1:
  print(ans[0][0],ans[0][1],ans[0][2])

Submission status: Accepted

Solution code:
import numpy as np
def solve(n, x, y, h):
    for cx in range(101):
        for cy in range(101):
            ok = False
            for i in range(n):
                if h[i] > 0:
                    H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                    ok = True
                    break
            if ok:
                for i in range(n):
                    h_i = max(H - abs(x[i] - cx) - abs(y[i] - cy), 0)
                    if h_i != h[i]:
                        ok = False
                        break
            if ok:
                return "%d %d %d" % (cx, cy, H)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from operator import itemgetter
def solve():
    Z = sorted([tuple(map(int,input().split())) for _ in range(int(input()))], key=itemgetter(2,0,1) , reverse=True)
    x0, y0, h0 = Z[0]
    H = h0 + np.abs(np.arange(101, dtype=int).reshape(101,1)-x0) + np.abs(np.arange(101, dtype=int).reshape(1,101)-y0)
    for (i,j), h in np.ndenumerate(H):
        if all(h == max(H[i,j]-abs(x-i)-abs(y-j), 0) for x,y,h in Z):
            return ' '.join(map(str, [i,j,h]))

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

Submission status: Accepted

Solution code:
# 全探索可能
# 座標の候補は101 * 101 通り *100座標ぶんなので。
# 0の場合どうするか
# 0以外で候補を列挙して、あとで合ってるか検証(方針合ってた)


def abs(key):
    if key < 0:
        return -key
    else:
        return key


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())
pos_max = 100  # 座標のmaxを定義
for posY in range(pos_max+1):
    for posX in range(pos_max+1):
        # needHは頂上がであるか判定する用
        # -1だとまだよくわからん
        # -2だと頂上ではない
        needH = -1
        # print("hoge", "posX", "posY", posX, posY)
        for i in range(n):
            if h[i] > 0:
                # この頂点からみて頂上がposX、posYの時
                # 頂上の高さを求める。
                tmp = h[i] + abs(posX-x[i]) + abs(posY-y[i])
                # print(i, "tmp", tmp)
                # print("h[i]", h[i], "x[i]", x[i], "y[i]", y[i])
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        # print(posX, posY, needH)
        # exit()
        if needH == -2:
            continue  # ダメだったら別の場所を探す
        # 高さが0の場合のチェック
        for i in range(n):
            if h[i] == 0:
                dist = abs(posX-x[i]) + abs(posY-y[i])
                if needH > dist:
                    needH = -2
                    break
        if needH == -2:
            continue
        print("{} {} {}".format(posX, posY, needH))

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
for i in range(0,n):
    X,Y,h = map(int,input().split())
    xyh.append((X,Y,h))
from operator import itemgetter
xyh.sort(key=itemgetter(2))
xyh.reverse()

ans = ()
for i in range(0,101):
    for j in range(0,101):
        flag = "f"
        x,y,h = xyh[0]
        H = h + abs(x-i)+abs(y-j)
        for x,y,h in xyh:
            if H ==  h + abs(x-i)+abs(y-j) and h != 0:
                flag = "t"
            elif H <=  h + abs(x-i)+abs(y-j) and h == 0:
                flag = "t"
            else:
                flag = "f"
                break
        if flag == "t":
            ans = (i,j,H)
Cx,Cy,H = ans
print(Cx,Cy,H)

Submission status: Accepted

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

for CX in range(0, 101):
    for CY in range(0, 101):
        H = -1
        for x, y, h in xyh:
            if h != 0:
                if H == -1:
                    H = abs(x - CX) + abs(y - CY) + h
                elif H != abs(x - CX) + abs(y - CY) + h:
                    break
            else:
                if H != -1 and H - abs(x - CX) - abs(y - CY) > 0:
                    break
        else:
            print(CX, CY, H)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
a.sort(key=lambda x:x[2], reverse=True)
ht = a[0][2]
x = a[0][0]
y = a[0][1]
ans = True
for i in range(100+1):
    for j in range(100+1):
        h = ht + abs(x-i) + abs(y-j)
        ans = True
        for case in a:
            if not case[2] == max(h - abs(case[0] - i) - abs(case[1] - j), 0):
                ans = False
                break
        if ans:
            break
    if ans:
        break
print(i, j, h)

Submission status: Accepted

Solution code:


def func():

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

    for cx in range(101):
        for cy in range(101):
            for line in data:
                if line[2] != 0:
                    x = line[0]
                    y = line[1]
                    h = line[2]
                    H_max = h + abs(cx - x) + abs(cy - y)
                    break
            flag = True
            for i in range(n):
                    x = data[i][0]
                    y = data[i][1]
                    h = data[i][2]
                    if h != 0:
                        if not H_max == h + abs(cx-x) + abs(cy-y):
                            flag = False
                            break
                    else:
                        if not H_max <=  abs(cx-x) + abs(cy-y):
                            flag = False
                            break
            if flag:
                print(cx,cy,H_max)
                return 0

func()

Submission status: Accepted

Solution code:
N, = map(int, raw_input().split())
x = [0]*N
y = [0]*N
h = [0]*N
for i in range(N):
  x[i], y[i], h[i] = map(int, raw_input().split())
for cx in range(101):
  for cy in range(101):
    for i in range(N):
      if h[i]!=0:
        H = h[i]+abs(x[i]-cx)+abs(y[i]-cy)
        break
    hit=True
    for i in range(N):
      ch = max(0, H-abs(x[i]-cx)-abs(y[i]-cy))
      if ch!=h[i]:
        hit=False
        break
    if hit:
      print cx, cy, H

Submission status: Accepted

Solution code:
import sys

N = int(input())

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())

# N = 4

# x = [2,2,1,3]
# y = [3,1,2,2]
# h = [5,5,5,5]

def dif(x,y,a,b):
    ans = int(abs(x-a) + abs(y-b))
    return(ans)


for i in range(N):
    if h[i] != 0:
        xt, yt, ht = x[i], y[i], h[i]
        break


for i in range(101):
    for j in range(101): # 頂点に関する全探索

        collect = True
        top = ht + dif(i, j, xt, yt)

        for k in range(N):
            h_predict = max(0, top - dif(x[k], y[k], i, j))

            if h[k] != h_predict:
                collect = False
                break

        if collect:
            print(i,j,top)
            sys.exit()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    p = [0] * n

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

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


    for x in range(0, 101):
        for y in range(0, 101):
            flag = True
            h = abs(x - p[0][0]) + abs(y - p[0][1]) + p[0][2]
            for xi, yi, hi in p:
                if hi != max([0, h - abs(x - xi) - abs(y - yi)]):
                    flag = False
                    break

            if flag:
                print('{} {} {} '.format(x, y, h))
                return
main()

Submission status: Accepted

Solution code:
import sys
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)
inf=2e31-1
for i in range(101):
    for j in range(101):
        judge=True
        H1=inf
        for k in range(n): 
            if h[k]!=0:
                H1=h[k]+abs(i-x[k])+abs(j-y[k])
                break

        for k in range(n):
            if h[k]==0:
                if H1>abs(i-x[k])+abs(j-y[k]):
                    judge=False
                    break
            else:
                H2=h[k]+abs(i-x[k])+abs(j-y[k])
                if H1!=H2:
                    judge=False
                    break
                    
        if judge:
            sys.stdout.write(str(i))
            sys.stdout.write(' ')
            sys.stdout.write(str(j))
            sys.stdout.write(' ')
            print(H1)
            sys.exit()

Submission status: Accepted

Solution code:
n = int(raw_input())
px = 0
py = 0
ph = 0
ls = []
for _ in range(n):
    x,y,h = map(int, raw_input().split())
    if ph == 0 and h != 0:
        px = x
        py = y
        ph = h
    ls.append((x,y,h))
ok = True
for cy in range(101):
    for cx in range(101):
        ch = ph + abs(cx - px) + abs(cy - py)
        ok = True
        for (x, y, h) in ls:
            if max(ch-abs(x-cx)-abs(y-cy), 0) != h:
                ok = False
                break
        if ok:
            print cx,cy,ch
            break
    if ok:
        break

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


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


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])
    D.sort()
    D.reverse()
    ans = solve()
    print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for x in range(101):
        for y in range(101):
            for h in range(h_min, h_min + 201):
                for i in range(N):
                    if D[i][0] != max(h - abs(D[i][1] - x) - abs(D[i][2] - y), 0):
                        break
                else:
                    return x, y, h


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
p = []
for i in range(N):
    X1, Y1, H1 = map(int, input().split())
    if H1 != 0:
        p.append([X1, Y1, H1])

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


for i in range(101):
    for j in range(101):
        h = -1
        fg = True
        for t in p:
            if h == -1:
                h = t[2] + abs(i - t[0]) + abs(j - t[1])

            else:
                ht = t[2] + abs(i - t[0]) + abs(j - t[1])
                if h == ht:
                    h = ht
                else:
                    fg = False
                    break
        if fg:
            print(i, j, h)

Submission status: Accepted

Solution code:
N = int(input())
pos = [list(map(int, input().split())) for _ in range(N)]
for cx in range(101):
    for cy in range(101):
        minH = 1 << 30
        se = set()
        for x,y,h in pos:
            a = -abs(x-cx)-abs(y-cy)
            if h == 0 and a == 0:
                break
            elif h == 0:
                minH = min(minH, -a)
            else:
                se.add(h-a)
        else:
            if len(se) == 0 and minH == 1:
                print(cx, cy, minH)
            elif len(se) == 1:
                hh = se.pop()
                if hh <= minH:
                   print(cx, cy, hh)

Submission status: Accepted

Solution code:
N = int(input())
p = []
for i in range(N):
    X1, Y1, H1 = map(int, input().split())
    if H1 != 0:
        p.append([X1, Y1, H1])

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


for i in range(101):
    for j in range(101):
        h = -1
        fg = True
        for t in p:
            if h == -1:
                h = t[2] + abs(i - t[0]) + abs(j - t[1])

            else:
                ht = t[2] + abs(i - t[0]) + abs(j - t[1])
                if h == ht:
                    h = ht
                else:
                    fg = False
                    break
        if fg:
            print(i, j, h)
            exit()

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
h = []
for i in range(N):
    a,b,c = [int(hoge) for hoge in input().split()]
    x.append(a)
    y.append(b)
    h.append(c)

cx = 0
cy = 0
H = 0
done_flag = False

for i in range(101):
    for j in range(101):
        # (x, y) = (i, j)
        cand_h = []
        min_h = []

        for k in range(N):
            if h[k] != 0:
                cand_h.append(h[k] + abs(x[k] - i) + abs(y[k] - j))
            else:
                min_h.append(abs(x[k] - i) + abs(y[k] - j))
                
        min_h = min(min_h) if len(min_h) > 0 else 100000000000
    
        if len(set(cand_h)) == 1 and list(set(cand_h))[0] <= min_h:
            print("{} {} {}".format(i, j, cand_h[0]))
            done_flag = True
            break
    if done_flag:
        break

Submission status: Accepted

Solution code:
n = int(input())
lis = []
for i in range(n):
  a = list(map(int,input().split()))
  if a[2] != 0:lis.append(a)
if len(lis) == 1:
  print(lis[0][0],lis[0][1],lis[0][2])
  exit()
for x in range(101):
  for y in range(101):
    co = abs(x -lis[0][0])+abs(y -lis[0][1])+lis[0][2]
    for j in range(1,len(lis)):
      if co != abs(x -lis[j][0])+abs(y -lis[j][1])+lis[j][2]:
        break
      if j == len(lis)-1:
        print(x,y,co)
        exit()

Submission status: Accepted

Solution code:
n=int(input())
lst=[]
for i in range(n):
    a=list(map(int,input().split()))
    if a[2]!=0:lst.append(a)
if len(lst)==1:
    print(*lst[0])
    exit()
for i in range(101):
    for j in range(101):
        h=abs(i-lst[0][0])+abs(j-lst[0][1])+lst[0][2]
        for k in lst[1:]:
            if h!=abs(i-k[0])+abs(j-k[1])+k[2]:break
        else:
            print(i,j,h)
            exit()

Submission status: Accepted

Solution code:
# Pyramid
n = int(input())
data = []
h_ = 0
for i in range(n):
    data.append(list(map(int, input().split())))
data = sorted(data, key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        for j in range(n):
            if j == 0:
                h_ = data[0][2] + abs(cx - data[0][0]) + abs(cy - data[0][1])
            else:
                if data[j][2] == max(0, h_ - abs(cx - data[j][0]) - abs(cy - data[j][1])):
                    if j == n - 1:
                        print('{0} {1} {2}'.format(cx, cy, h_))
                        exit()
                    else:
                        continue
                else:
                    break

Submission status: Accepted

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

for i in range(n):
    if li[i][2] != 0:
        h1 = li[i][2]
        break

flag = True
flag2 = False

for i in range(10**9):
    if flag2 == True: break
    for X in range(101):
        for Y in range(101):
            h = h1 + i
            flag = True
            for j in range(n):
                if max(h - abs(li[j][0]-X) - abs(li[j][1]-Y),0) != li[j][2]:
                    flag = False
                    break
            if flag == True:
                print(X,Y,h)
                flag2 = True
            if flag2 == True: break
            h = h1 - i
            flag = True
            for j in range(n):
                if max(h - abs(li[j][0]-X) - abs(li[j][1]-Y),0) != li[j][2]:
                    flag = False
                    break
            if flag == True:
                print(X,Y,h)
                flag2 = True

Submission status: Accepted

Solution code:
N=int(input())
xyh=[]
for i in range(N):
    a=[int(i) for i in input().split()]
    xyh.append(a)
xyh.sort(key=lambda x:x[2],reverse=True)
flag2=True
for i in range(0,101):
    for j in range(0,101):
        flag=True
        H=xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in range(1,N):
            if xyh[k][2]!=max(0,H-abs(xyh[k][0]-i)-abs(xyh[k][1]-j)):
                flag=False
                break
        if flag==True:
            print("{} {} {}".format(i,j,H))
            flag2=False
            break
    if flag2==False:
        break

Submission status: Accepted

Solution code:
N=int(input())

A=[]
for i in range(N):
  a,b,c=map(int,input().split())
  A.append([a,b,c])
  
A=sorted(A,key=lambda x:-x[2])

for x in range(101):
  for y in range(101):
    cntH=abs(x-A[0][0])+abs(y-A[0][1])+A[0][2]
    ans=True
    for i in range(1,N):
      if (A[i][2]>0 and cntH-abs(x-A[i][0])-abs(y-A[i][1]) != A[i][2]) or (cntH-abs(x-A[i][0])-abs(y-A[i][1])>0 and A[i][2]==0):
        ans=False
        break
    if ans:
      print(x,y,cntH)
      break

Submission status: Accepted

Solution code:
r=range(int(input()))
p=[[int(i)for i in input().split()] for _ in r]
p.sort(key=lambda x: x[2])
a,b,c=p[-1]
for x in range(101):
  for y in range(101):
    h=c+abs(a-x)+abs(b-y)
    if all(k==max(h-abs(i-x)-abs(j-y),0) for i,j,k in p):
      print(x,y,h)
      exit()

Submission status: Accepted

Solution code:
def execute() :
    n = int(input())
    p = [[int(i) for i in input().split()] for i in range(n)]
    
    for posX in range(101) :
        for posY in range(101) :
            needH = -1
    
            for i in range(n) :
                x, y, h = p[i]
                if h > 0 :
                    tmp = h + abs(posY-y) + abs(posX-x)
                    if needH == -1 :
                        needH = tmp
                    else :
                        if needH != tmp :
                            needH = -2
                            break
            if needH == -2 : 
                continue
    
            for i in range(n) :
                x, y, h = p[i]
                if h == 0 :
                    dist =  abs(posY-y) + abs(posX - x)
                    if needH > dist :
                        needH = -2
                        break
            if needH == -2 : 
                continue
            
            return (posX, posY, needH)

result = execute()     
print(result[0], result[1], result[2])

Submission status: Accepted

Solution code:
def f(x, y, cx, cy):
    return abs(cx - x) + abs(cy - y)

n = int(input())
x = [0]*n
y = [0]*n
h = [0]*n
MAX = 2*(10**9)
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):
        maxH = MAX
        res = 0
        isAnswer = True
        for i in range(n):
            if h[i] == 0:
                maxH = min(maxH, f(x[i], y[i], cx, cy))
            else:
                curH = h[i] + f(x[i], y[i], cx, cy)
                if res == 0:
                    res = curH
                elif curH != res:
                    isAnswer = False
                    break
        if isAnswer and res <= maxH:
            print(cx, cy, res)
            cy = cx = 101

Submission status: Accepted

Solution code:
n = int(input())
xyh = [tuple(int(x) for x in input().split()) for _ in range(n)]

base = [0,0,0]
for x, y, h in xyh:
    if h > 0:
        base = [x,y,h]

for i in range(101):
    for j in range(101):
        top_h = abs(i - base[0]) + abs(j - base[1]) + base[2]
        check = 1
        for x, y, h in xyh:
            if max(top_h - abs(i - x) - abs(j - y), 0) != h:
                check = 0
                break
        if check == 1:
            print(i, j, top_h)
            exit()

Submission status: Accepted

Solution code:
def f(n,xyh):
	for i in range(n):
		if xyh[i][2]:
			xs,ys,hs=xyh[i]

	for Cx in range(101):
		for Cy in range(101):
			H=hs+abs(xs-Cx)+abs(ys-Cy)
			
			for i in range(n):
				if xyh[i][2] != max(H-abs(xyh[i][0]-Cx)-abs(xyh[i][1]-Cy),0):
					break
			else:
				return '{} {} {}'.format(Cx,Cy,H)

if __name__=="__main__":
	x=int(input())
	data=[[int(j) for j in input().split()] for i in range(x)]
	print(f(x,data))

Submission status: Accepted

Solution code:
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N = read()
x = []
y = []
h = []
for i in range(N):
    xi, yi, hi = readmap()
    x.append(xi)
    y.append(yi)
    h.append(hi)
    if hi > 0:
       idx = i

for cx in range(101):
    for cy in range(101):
        H = h[idx] + abs(x[idx] - cx) + abs(y[idx] - cy)
        ok = True
        for i in range(N):
            if h[i] != max(0, H - abs(x[i] - cx) - abs(y[i] - cy)):
                ok = False
                break
        if ok:
            print(cx, cy, H)
            quit()

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 = None
        for x, y, h in Info:
            if h == 0:
                continue

            # hが0以外の情報からHを一意に定める
            tmp_H = abs(Cx - x) + abs(Cy - y) + h
            if (H is None) or (H == tmp_H):
                H = tmp_H
            else:
                break
        # Hが一意に定まっていればh=0の情報すべてと整合性が取れているかチェック
        else:
            for x, y, h in Info:
                if h != 0:
                    continue

                if H - abs(Cx - x) - abs(Cy - y) > 0:
                    break

            # 整合性がとれていれば終わり
            else:
                print(Cx, Cy, H)
                exit()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        for l in lst:
            if l[2] != 0:
                H = abs(cx-l[0]) + abs(cy-l[1]) + l[2]
        for l in lst:
            if l[2] != max(0, H - abs(cx-l[0]) - abs(cy-l[1])):
                break
        else:
            print(cx, cy, H)
            exit(0)

Submission status: Accepted

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

def main():
    n = int(input())
    arrys = [tuple(map(int, input().split())) for _ in range(n)]
    for i in range(101):
        for j in range(101):
            for x_tmp, y_tmp, h_tmp in arrys:
                if h_tmp != 0:
                    break
            H = h_tmp + abs(x_tmp - i) + abs(y_tmp - j)
            for x_t, y_t, h_t in arrys:
                if h_t != max(H - abs(x_t - i) - abs(y_t - j), 0):
                    break
            else:
                print(i, j, H)
                exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def main():
    """
    1 <= N      <= 100
    0 <= xi, yi <= 100
    0 <= hi     <= 10^9
    """
    N = int(input())
    x, y, h = zip(*(
        map(int, input().split())
        for _ in range(N)
    ))

    if "PyPy" in sys.version:
        ans4 = loop_xyh_N(x, y, h)
        print(*ans4)
    else:
        # ans = no_sub(x, y, h)
        ans1 = editorial_movie(x, y, h)
        ans2 = editorial_pdf(x, y, h)
        ans3 = ref_sub_xyn(x, y, h)
        print(*ans2)
        assert ans1 == ans2 == ans3


def h_H(cx, cy, x, y):
    return - abs(x - cx) - abs(y - cy)


def no_sub(x, y, h):
    max_h = -1
    ans = None
    dict_h = {(_x, _y): _h for _x, _y, _h in zip(x, y, h)}
    for _x, _y, _h in zip(x, y, h):
        for cx in range(1, 100+1):
            for cy in range(1, 100+1):
                tmp = h_H(cx, cy, _x, _y)
                pos = (cx, cy)
                H = _h - tmp
                if pos in dict_h and H != dict_h[pos]:
                    continue

                if H > max_h:
                    max_h = H
                    ans = _x, _y, H

                # print((_x, _y), (cx, cy), _h, tmp, sep="\t")

    return ans


def editorial_movie(x, y, h):
    """
    H >= 1, これ重要
        コンテスト中にこれを意識していなかった
        入力の制約しか意識していなかった

    h(x, y) = max(H - |x - Cx| - |y - Cy|, 0)
    より
        h(x,y) > 0:
            H            - |x - Cx| - |y - Cy| > 0
            H  = h(x, y) + |x - Cx| - |y - Cy|
        h(x,y) = 0:
            H            - |x - Cx| - |y - Cy| <= 0
            H <= h(x, y) + |x - Cx| + |y - Cy|
            頂点なら制約を満たしていない
    """
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 頂上がどれくらいの高さであってほしいか。
            # -1はまだ良く分からない時。0以上は確定してるとき
            # -2はダメだって分かった時
            need_h = -1

            # h=0 より大きい場合の検証
            for _x, _y, _h in zip(x, y, h):
                if not _h > 0:
                    continue

                # 頂点候補座標および調査座標の組合せにおいてHになるべき値
                tmp = _h + abs(_x - cx) + abs(_y - cy)
                if need_h == -1:
                    need_h = tmp
                elif need_h != tmp:
                    need_h = -2
                    break

            if need_h == -2:
                continue

            # h=0 の検証
            for _x, _y, _h in zip(x, y, h):
                if not _h == 0:
                    continue

                # _h == 0 より、計算式上では省略してマンハッタン距離のみ求めている
                dist = abs(_x - cx) + abs(_y - cy)
                if need_h > dist:
                    need_h = -2
                    break

            if need_h == -2:
                continue

            return cx, cy, need_h


def ref_sub_xyn(x, y, h):
    """
    https://beta.atcoder.jp/contests/abc112/submissions/3348987
    """
    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 頂点候補をだしておき、0なら1に補正して確実に頂点候補とする
            # h_min, h_max は矛盾の確認用に２つ用意
            h_min = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
            h_max = h_min
            if h[0] == 0:
                h_min = 1

            for _x, _y, _h in zip(x[1:], y[1:], h[1:]):
                # min: TODO
                h_max = min(h_max, _h + abs(_x - cx) + abs(_y - cy))
                if _h != 0:
                    h_min = max(h_min, _h + abs(_x - cx) + abs(_y - cy))

            if h_min == h_max:
                return cx, cy, h_min


def editorial_pdf(x, y, h):
    """
    条件を満たすピラミッドがただ 1 つなのであれば、必ず以下のものが 1 個以上存在します。
        • 調査で得られた情報のうち、hi ≥ 1 を満たす情報 (xi, yi, hi)。

    なぜなら、全部 hi = 0 であるとき、
    調査を行っていない整数座標を中心とする高さ 1 のピラミッドが条件を満たしてしまうので、
        最低でも 101×101− N 個、N = 100 の場合 10, 101 個以上の条件を満たすピラミッドが存在することになるからです。
        そこで、前述の条件を満たす情報のうち 1 個を (xt, yt, ht) とおきます。
    """
    # 候補, 調査点の高さ0のときはない（解説より）
    gx, gy, gh = (-1, -1, -1)
    for _x, _y, _h in zip(x, y, h):
        if _h >= 1:
            gx, gy, gh = _x, _y, _h

    for cx in range(100 + 1):
        for cy in range(100 + 1):
            v = gh + abs(gx - cx) + abs(gy - cy)
            v = max(v, 0)
            flag = True

            for _x, _y, _h in zip(x, y, h):
                # _h との検証
                vv = v - abs(_x - cx) - abs(_y - cy)
                vv = max(vv, 0)
                if _h != vv:
                    flag = False

            if flag:
                return cx, cy, v


def loop_xyh_N(x, y, h):
    h_base = max(h)

    for cx in range(100 + 1):
        for cy in range(100 + 1):
            # 探索範囲100x100より、調査点の候補より200以内
            for ch in range(h_base, h_base + 200 + 1):
                ok = True
                for _x, _y, _h in zip(x, y, h):
                    tmp = _h + abs(_x - cx) + abs(_y - cy)
                    if _h > 0 and ch != tmp:
                        ok = False
                        break
                    elif _h == 0 and ch > tmp:
                        ok = False
                        break

                if ok:
                    return cx, cy, ch


def f2(x, y, h):
    chs = []
    for _x, _y, _h in zip(x, y, h):
        for cx in range(0, 100 + 1):
            for cy in range(0, 100 + 1):
                tmp = h_H(cx, cy, _x, _y)
                print((_x, _y), (cx, cy), _h, tmp, sep="\t")

    return 1


if __name__ == '__main__':
    main()