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: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
XYH = [list(map(int,input().split())) for _ in range(N)]

Cxy = defaultdict(int)

#-1 NG
# 0 default
#1+ ok
verify =[]
for x,y,h in XYH:
    for cx in range(101):
        for cy in range(101):
            val = Cxy[(cx,cy)]
            if val<0:
                continue
            tmp_H = abs(x-cx)+abs(y-cy)+h
            if h==0:
                verify.append((x,y,h))
                continue #????

            if val==0:
                Cxy[(cx,cy)] = tmp_H
            elif val != tmp_H:
                Cxy[(cx, cy)] =-1

def find(d):
    for key in d.keys():
        if d[key] >0:

            if any((d[key]-abs(key[0]-x) - abs(key[1]-y))>0  for x,y,h in verify):
                continue

            return key,d[key]

(X,Y),H = find(Cxy)
print(X,Y,H)

Submission status: Time Limit Exceeded

Solution code:
# encoding: utf-8
import itertools


n = int(input())
xlist = []
ylist = []
hlist = []
for i in range(n):
	xtmp, ytmp, htmp = map(int, input().split())
	xlist.append(xtmp)
	ylist.append(ytmp)
	hlist.append(htmp)
h = 0
end_flag = False
while True:
	for cx, cy in itertools.product(range(101), range(101)):
		if all([hlist[i] == max(h - abs(xlist[i] - cx) - abs(ylist[i] - cy), 0) for i in range(n)]):
			print('{} {} {}'.format(cx, cy, h))
			end_flag = True
			break
	if end_flag:
		break
	h += 1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = []
y = []
h = []
for i in range(N):
    x_i, y_i, h_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)
    h.append(h_i)

#i:情報番号 j:求めるx座標 k:求めるy座標 l:求める高さ
for j in range(101):
    for k in range(101):
        for l in range(h[0] - 200, h[0] + 200):
            flag = 1
            for i in range(N):
                h_i_test = max(l - abs(x[i] - j) - abs(y[i] - k), 0)
                if h_i_test != h[i]:
                    flag = 0
            if flag == 1:
                print(str(j)+ " " + str(k) + " " + str(l))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

x = []

for i in range(n):
	x.append(list(map(int,input().split())))
a = x[0][2]
b = 0
for i in range(101):
	for j in range(101):
		for k in range(a,a+201):
			for l in x:
				if l[2] == max(0,k-abs(i-l[0])-abs(j-l[1])):
					b += 1
			if b == n:
				print(i,j,k)
			b = 0

Submission status: Time Limit Exceeded

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)

H = 1
c_x = 0
c_y = 0
f = 1

while f == 1:
    for i in range(101):
        for j in range(101):
            for k in range(N):
                if x[k] - i < 0:
                    x_1 = i - x[k]
                else:
                    x_1 = x[k] - i
                if y[k] - j < 0:
                    y_1 = j - y[k]
                else:
                    y_1 = y[k] - j
                if h[k] == H - x_1 - y_1:
                    c_x = i
                    c_y = j
                    if k == N - 1:
                        f = 0
                else:
                    c_x = 0
                    c_y = 0
                    break
            if f == 0:
                break
        if f == 0:
            break
    H += 1

print(c_x, c_y, H-1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def get_cands(x, y, h):
    if h > 0:
        for xc in range(100 + 1):
            for yc in range(100 + 1):
                hc = h + abs(xc - x) + abs(yc - y)
                if hc <= 10**9:
                    yield (xc, yc, hc)
    else:
        for xc in range(100 + 1):
            for yc in range(100 + 1):
                hc = h + abs(xc - x) + abs(yc - y)
                for hc2 in range(1, hc + 1):
                    if hc <= 10**9:
                        yield (xc, yc, hc2)

x1, y1, h1 = map(int, input().split())
cand = set(get_cands(x1, y1, h1))

for _ in range(N - 1):
    new_cand = set()
    x, y, h = map(int, input().split())
    for c in get_cands(x, y, h):
        if c in cand:
            new_cand.add(c)
    cand = new_cand
    if len(cand) == 1:
        break
if len(cand) == 1:
    print(*next(iter(cand)))
else:
    while True:
        pass

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
hs=[xyh[i][-1] for i in range(n)]
mh=min(hs)
if mh==0:
    mh=1
for cx in range(101):
    for cy in range(101):
        for h in range(mh,mh+201):
            j=True
            for i in range(n):
                if max(h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy),0)!=xyh[i][2]:
                    j=False
            if j:
                print(cx,cy,h)
                break

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    L = [LI() for i in range(N)]
    
    for x in range(101):
        for y in range(101):
            max_num = float('inf')
            ans = 0
            res = True
            for xn, yn, hn in L:
                if hn == 0:
                    max_num = min(max_num, abs(x-xn)+abs(y-yn))
                    if max_num == 0:
                        res = False
                        break
                else:
                    temp = abs(x-xn)+abs(y-yn)+hn
                    if ans != 0 and ans != temp:
                        res = False
                        break
                    else:
                        ans = temp
            if (max_num >= 2 and ans == 0) or ans > max_num:
                res = False

            if res:
                if ans != 0:
                    print(x,y,ans)
                else:
                    print(x,y,1)
                exit()
    
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
list_XYH1, list_XYH = [ list(map(int,input().split(" "))) for _ in range(n)], []
for x, y, h in list_XYH1:
    if h != 0:
        list_XYH.append([x, y, h])

for i in range(0, 101):
    for j in range(0, 101):
        cnt = 0
        x, y, h = list_XYH[0]
        H = h + abs(i - x) + abs(j - y)
        for x, y, h in list_XYH:
            if h + abs(i - x) + abs(j - y) == H:
                cnt += 1

        if cnt == len(list_XYH) and cnt != 0 and cnt != 1:
            print(i, j, H)
            exit()

list_XYH2 = []
m = pow(10, 10)
for x, y, h in list_XYH1:
    m = min(m, h)
    list_XYH2.append([x, y, h])

for X in range(0, 101):
    for Y in range(0, 101):
        for H in range(m, m + 201):
            cnt = 0
            for x, y, h in list_XYH2:
                if max(H - abs(x - X) - abs(y - Y), 0) == h:
                    cnt += 1

            if cnt == n:
                print(X, Y, H)
                exit()

Submission status: Accepted

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

test = [(x,y,h) for x,y,h in xyh if h > 0]
test = test[0]
for cx in range(101):
    for cy in range(101):
        # h > 0で中心座標の高さを見積もる
        x,y,h = test
        H = h + abs(x - cx) + abs(y - cy)

        # 全データに適合するか        
        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())
Q = [list(map(int, input().split())) for _ in range(N)]
Q.sort(key=lambda x: x[2])
a, b, H = Q[-1]


def height(x, y, H, a, b):
    return max(H-abs(x-a)-abs(y-b), 0)


for i in range(101):
    for j in range(101):
        A = H+abs(i-a)+abs(j-b)
        B = height(a, b, H, i, j)
        f, g = True, True
        if not A:
            f = False
        if not B:
            g = False
        for k in range(N):
            x, y, h = Q[k]
            if height(i, j, A, x, y) != h:
                f = False
            if height(i, j, B, x, y) != h:
                g = False
            if not (f or g):
                break
        else:
            if f:
                print(i, j, A)
                exit()
            else:
                print(i, j, B)
                exit()

Submission status: Accepted

Solution code:
N=int(input())
hyx=[list(map(int,input().split()))[::-1]for _ in range(N)]
R=range(101)
for X in R:
    for Y in R:
        h,y,x=max(hyx)
        H=h+abs(X-x)+abs(Y-y)
        if all(h==max(H-abs(X-x)-abs(Y-y),0)for h,y,x in hyx):
            print(X,Y,H)

Submission status: Accepted

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

def check(cx, cy):
  H = None
  fin = []
  for i in info:
    x = i[0]
    y = i[1]
    h = i[2]
    if h != 0:
      tmpH = h + abs(x-cx) + abs(y-cy)
      if H:
        if H != tmpH:
          return 0
      else:
        H = tmpH
    else:
      fin.append((x, y, h))
  for f in fin:
    x = f[0]
    y = f[1]
    if H - abs(x-cx) -abs(y-cy) > 0:
      return 0
  return H
      

for cx in range(101):
  for cy in range(101):
    h = check(cx, cy)
    if h >= 1:
      print(cx)
      print(cy)
      print(h)
      break

Submission status: Accepted

Solution code:
n = int(input())

xl = [0]*n
yl = [0]*n
hl = [0]*n


for i in range(n):
    xl[i], yl[i], hl[i] = map(int, input().split())
    if hl[i] >= 1:
        si = i

ansx, ansy, ansh = -1, -1, -1

for cx in range(101):
    for cy in range(101):
        H = hl[si]+abs(xl[si]-cx)+abs(yl[si]-cy)
        flag = True
        for i in range(n):
            hi = max(H-abs(xl[i]-cx)-abs(yl[i]-cy), 0)
            if hi != hl[i]:
                flag = False
                break
        if flag:
            ansx, ansy, ansh = cx, cy, H
print(ansx, ansy, ansh)

Submission status: Accepted

Solution code:
N=int(input())
xyh=[list(map(int,input().split()))for _ in range(N)]
hxy=[[h,x,y]for x,y,h in xyh]
hxy.sort()
for X in range(101):
    for Y in range(101):
        h,x,y=hxy[-1]
        H=h+abs(X-x)+abs(Y-y)
        if all(h==max(H-abs(X-x)-abs(Y-y),0)for h,x,y in hxy):
            print(X,Y,H)

Submission status: Accepted

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

for i in range(101):
    for j in range(101):
        s = -1
        flag = True
        limit = float('inf')
        for x, y, h in xyh:
            if h != 0:
                H = h + abs(x-i) + abs(y-j)
                if s != -1:
                    if s != H:
                        flag = False
                        break
                s = H
            else:
                limit = min(limit, abs(x-i) + abs(y-j))
        if flag:
            if s != -1 and s <= limit:
                print(i, j, s)
                exit()
            elif s <= limit and limit == 1:
                print(i, j, 1)
                exit()

Submission status: Accepted

Solution code:
N = int(input()); INF = float("inf")
Z = []
S = set([])
for i in range(N):
  x,y,h = map(int,input().split())
  Z.append((x,y,h))
  S.add((x,y))
Z.sort(key=lambda x : x[2],reverse=True)
#print(Z)
for i in range(101):
  for j in range(101):
    #Flag = True #0以外があればFalse
    MAX = INF
    for t in range(N):
      #print(Z[t][2])
      if t == 0: #最初は必ず0以外。
        ans = abs(i-Z[t][0])+abs(j-Z[t][1])+Z[t][2]
      elif Z[t][2] == 0:
        MAX = min(MAX,abs(i-Z[t][0])+abs(j-Z[t][1])+Z[t][2])
      else:
        temp = abs(i-Z[t][0])+abs(j-Z[t][1])+Z[t][2]
        if temp != ans:
          break
      if t != N-1: #最後じゃないなら続く。
        continue
      #print(i,j,MAX,ans)
      if ans <= MAX:
        ret = [i,j,ans]
        print(*ret);exit()
      else:
        break

Submission status: Accepted

Solution code:
def resolve():
    n=int(input())
    xyh=[list(map(int,input().split())) for _ in range(n)]
    xyh.sort(key=lambda x:x[2],reverse=True)
    ans=[]
    for cx in range(101):
        for cy in range(101):
            x,y,h=xyh[0]
            ch=h+abs(x-cx)+abs(y-cy)
            if all([h==max(ch-abs(x-cx)-abs(y-cy),0) for x,y,h in xyh[1:]]):
                ans=[cx,cy,ch]
                break
    print(*ans)
resolve()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        h = -1
        for i in range(n):
            if info[i][2] != 0:
                h = info[i][2] + abs(info[i][0] - cx) + abs(info[i][1] - cy)
                break
        ok = True
        for i in range(n):
            v = max(h - abs(info[i][0] - cx) - abs(info[i][1] - cy), 0)
            ok &= v == info[i][2]
        if ok:
            print(cx, cy, h)
            exit()

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


# MOD = 10 ** 9 + 7
MOD = 998244353
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    xyh = [il() for _ in range(N)]

    for cx in range(0, 101):
        for cy in range(0, 101):
            tmp_x, tmp_y, tmp_h = -1, -1, -1
            for x, y, h in xyh:
                # 高さが1以上の調査点から
                # ピラミッドの中心を求める
                if h == 0:
                    continue
                tmp_x, tmp_y = cx, cy
                tmp_h = h + abs(x - cx) + abs(y - cy)
                break

            if tmp_h != -1:
                # 求めた中心が全ての調査点の条件と
                # 一致するか否かを確かめる
                for x, y, h in xyh:
                    if h != max(tmp_h - abs(x - tmp_x) - abs(y - tmp_y), 0):
                        break
                else:
                    print(tmp_x, tmp_y, tmp_h)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


# MOD = 10 ** 9 + 7
MOD = 998244353
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    xyh = [il() for _ in range(N)]

    for cx in range(0, 101):
        for cy in range(0, 101):
            tmp_x, tmp_y, tmp_h = -1, -1, -1
            for x, y, h in xyh:
                if h == 0:
                    continue
                tmp_x, tmp_y = cx, cy
                tmp_h = h + abs(x - cx) + abs(y - cy)
                break

            if tmp_h != -1:
                for x, y, h in xyh:
                    if h != max(tmp_h - abs(x - tmp_x) - abs(y - tmp_y), 0):
                        break
                else:
                    print(tmp_x, tmp_y, tmp_h)
                    exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        ch = h + abs(x - cx) + abs(y - cy)
        if all([h == max(ch - abs(x - cx) - abs(y - cy), 0) for x, y, h in xyh[1:]]):
            ans = [cx, cy, ch]
            break
print(*ans, sep=' ')

Submission status: Accepted

Solution code:
n = int(input())
xyh = []
x0, y0, h0 = None, None, None
for _ in range(n):
    x, y, h = map(int, input().split())
    if h > 0 and x0 is None:
        x0, y0, h0 = x, y, h
    xyh.append([x, y, h])

for cx in range(101):
    for cy in range(101):
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        done = True
        for xk, yk, hk in xyh:
            h_ = max(h - abs(xk - cx) - abs(yk - cy), 0)
            if h_ != hk:
                done = False
                break
        if done:
            print(f'{cx} {cy} {h}')

Submission status: Accepted

Solution code:
# 解説を参考に作成
# https://atcoder.jp/contests/abc112/submissions/16922570 を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, xyh):
    xyh.sort(reverse=True, 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:
                if h != max(0, H - abs(X - x) - abs(Y - y)):
                    break
            else:
                print(X, Y, H)
                return


if __name__ == '__main__':
    N = int(input())
    xyh = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, xyh)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    xyh = [list(map(int, input().split())) for _ in range(n)]
    xyh.sort(key = lambda x:x[2], reverse = True)
    x_ = xyh[0][0]
    y_ = xyh[0][1]
    h_ = xyh[0][2]
    for i in range(101):
        for j in range(101):
            top = h_ + abs(i - x_) + abs(j - y_)
            for x, y, h in xyh[1:]:
                h_2 = top - abs(i - x) - abs(j - y)
                if h != max(h_2, 0):
                    break
            else:
                print(i, j, top)
                return
                
main()

Submission status: Accepted

Solution code:
N=int(input())
x=[]
y=[]
h=[]
for _ in range(N):
    a,b,c=map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)
k=0
for i in range(N):
    if h[i]!=0:
        k=i
        break
for cx in range(101):
    for cy in range(101):
        H=h[k]+abs(x[k]-cx)+abs(y[k]-cy)
        for i in range(N):
            if max(H-abs(x[i]-cx)-abs(y[i]-cy),0)!=h[i]:
                break
        else:
            print(cx,cy,H)
            break
    else:
        continue
    break

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	info = []
	for i in range(N):
		x, y, h = [int(a) for a in input().split(" ")]
		info.append({"x": x, "y": y, "h": h})
	info.sort(key=lambda f: -f["h"])
	for cx in range(101):
		for cy in range(101):
			H = 0
			for i in range(len(info)):
				h = info[i]["h"] + abs(info[i]["x"] - cx) + abs(info[i]["y"] - cy)
				if i == 0:
					H = h
				else:
					if h != H:
						if (info[i]["h"] == 0 and h < H) or (info[i]["h"] > 0):
							break
			else:
				print(cx, cy, H)
				return 0
	if info[0]["x"] in [0, 100] and info[0]["y"] in [0, 100]:
		print(info[0]["x"], info[0]["y"], info[0]["h"])
		return 0

main()

Submission status: Accepted

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

for Cx in range(101):
    for Cy in range(101):
        criteria = -1
        ax, ay, ah = 0, 0, 0
        cnt = 0
        for x, y, h in xyh:
            if h == 0:
                continue
            H = h + abs(x - Cx) + abs(y - Cy)
            if H == criteria or criteria == -1:
                criteria = H
                ax, ay, ah = x, y, h
                cnt += 1
                continue
            else:
                break
        else:
            if cnt == 1:
                print(ax, ay, ah)
                exit()
            else:
                print(Cx, Cy, criteria)

Submission status: Accepted

Solution code:
N = int(input())
xyh = [list(map(int,input().split())) for i in range(N)]
f = False
for x in range(101):
    for y in range(101):
        for i in range(N):
            if xyh[i][2] != 0:
                H = abs(xyh[i][0]-x) + abs(xyh[i][1]-y) + xyh[i][2]
                break
        for i in range(N):
            if xyh[i][2] == 0 and H - abs(xyh[i][0]-x) - abs(xyh[i][1]-y) > 0:
                break
            if xyh[i][2] != 0 and H != abs(xyh[i][0]-x) + abs(xyh[i][1]-y) + xyh[i][2]:
                break
        else:
            f = True
            break
    if f:
        break
print(x,y,H)

Submission status: Accepted

Solution code:
n=int(input())
high=[]
for _ in range(n):
  a=list(map(int,input().split()))
  high.append(a)
inf=float('inf')
  
for x in range(0,101):
  
  for y in range(0,101):
    highlimit=inf
    ans=-1
    ch=-1
    for hi1 in high:
      p,q,r=hi1
      g=r+abs(p-x)+abs(q-y)
      if r<=0:
        G=abs(p-x)+abs(q-y)
        if ans>G:
          ch+=1
          break
        if G<=highlimit:
          highlimit=G
        
        continue
      else:
        if g>highlimit:
          ch+=1
          break
        else:
          if ans!=-1 and ans!=g:
            ch+=1
            break
          else:
            ans=g
    
    if ans!=-1 and ch==-1:
      print(x,y,ans)
      exit()

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	info = []
	for i in range(N):
		x, y, h = [int(a) for a in input().split(" ")]
		info.append({"x": x, "y": y, "h": h})
	info.sort(key=lambda f: -f["h"])
	for cx in range(101):
		for cy in range(101):
			H = 0
			for i in range(len(info)):
				h = info[i]["h"] + abs(info[i]["x"] - cx) + abs(info[i]["y"] - cy)
				if i == 0:
					H = h
				else:
					if h != H:
						if (info[i]["h"] == 0 and h < H) or (info[i]["h"] > 0):
							break
			else:
				print(cx, cy, H)
				return 0
	if info[0]["x"] in [0, 100] and info[0]["y"] in [0, 100]:
		print(info[0]["x"], info[0]["y"], info[0]["h"])
		return 0

main()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())

def run():
    N = int(sysread())
    V = []
    x0, y0, h0 = None, None, None
    for _ in range(N):
        x,y,h = mapline()
        if h > 0 and x0 == None:
            x0, y0, h0 = x,y,h
        V.append((x, y, h))

    for x in range(0, 101):
        for y in range(0, 101):
            H = h0 + abs(x0-x) + abs(y0-y)
            done = True
            for xk, yk, hk in V:
                h_ = max(H - abs(xk-x) - abs(yk-y), 0)
                if h_ != hk:
                    done = False
                    break
            if done:
                print(f'{x} {y} {H}')
                return


if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N=intput()
data1=[]
data2=[]
for _ in range(N):
    x,y,h=mint()
    if h>0:
        data1.append([x,y,h])
    else:
        data2.append([x,y])
for cx,cy in product(range(0,101),repeat=2):
    sup=INF
    for x,y in data2:
        sup=min(sup,abs(x-cx)+abs(y-cy))
    x,y,h=data1[0]
    H=abs(x-cx)+abs(y-cy)+h
    tmp=True
    for x,y,h in data1[1:]:
        if abs(x-cx)+abs(y-cy)+h!=H:
            tmp=False
            break
    if tmp and H<=sup:
        print(cx,cy,H)
        exit()

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    l = [i_list() for i in range(n)]

    L = []

    for i in l:
        if i[2] != 0:
            L.append(i)
    if len(L) == 1:
        print(" ".join(map(str, L[0])))
        exit()

    for x in range(101):
        for y in range(101):
            H = L[0][2] + abs(x-L[0][0]) + abs(y-L[0][1])
            flg = True
            for x1, y1, h1 in L[1:]:
                if h1 == 0:
                    pass
                if H != h1 + abs(x-x1) + abs(y-y1):
                    flg = False
                    break
            if flg == True:
                ans = [x,y]
    H = L[0][2] + abs(ans[0]-L[0][0]) + abs(ans[1]-L[0][1])
    print(" ".join(map(str, ans)) +" "+str(H))


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())

xl=[]
yl=[]
hl=[]



for i in range(n):
    xx,yy,hh=list(map(int,input().split()))
    xl.append(xx)
    yl.append(yy)
    hl.append(hh)

for cx in range(0,101):
    for cy in range(0,101):
        ok=True
        for i in range(n):
            x=xl[i]
            y=yl[i]
            h=hl[i]
            if h!=0:
                high = h + abs(x - cx) + abs(y - cy)
                break

        for i in range(n):
            x=xl[i]
            y=yl[i]
            h=hl[i]
            oh=max(high-abs(x-cx)-abs(y-cy),0)
            if h!=oh:
                ok=False
                break
        if ok:
            print(cx,cy,high)
            exit()