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:
N=int(input())
xyh=[list(map(int, input().split())) for _ in range(N)]
maxh = max([h for _,_,h in xyh])

def find(cx, cy, H):
	for x,y,h in xyh:
		if h != max(H-abs(x-cx)-abs(y-cy), 0):
			return False
	return True

def all():
	for cx in range(101):
		for cy in range(101):
			for H in range(min(1, maxh-200), maxh+201):
				if find(cx, cy, H):
					print("%d %d %d" % (cx, cy, H))
					return
	print("NOT FOUND")

all()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
data = [list(map(int,(input().split()))) for j in range(n)]
min_h = 10**10
for i in range(n):
    min_h = min(min_h,data[i][2])

def IsChusin(cx,cy,ch):
    for d in data:
        if d[2] != max(ch-abs(d[0]-cx)-abs(d[1]-cy),0):
            return False
    return True

for x in range(101):
    for y in range(101):
        for h in range(min_h,min_h+201):
            if IsChusin(x,y,h):
                print(x,y,h)

Submission status: Time Limit Exceeded

Solution code:
def abc(n:int,lst:list):
    l=list(map(lambda x:x[2],lst))
    if min(l)==0:
        M=max(map(lambda x:x[0],lst))+max(map(lambda x:x[1],lst))
        for x in range(101):
            for y in range(101):
                for h in range(M):
                    for i in range(n):
                        if max(0,h-abs(lst[i][0]-x)-abs(lst[i][1]-y)) ==lst[i][2]:
                            if i ==n-1:
                                return x,y,h
                        else:
                            break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)

Submission status: Time Limit Exceeded

Solution code:
def abc(n:int,lst:list):
    l=list(map(lambda x:x[2],lst))
    if min(l)==0:
        Mx=max(map(lambda x:x[0],lst))
        My=max(map(lambda x:x[1],lst))
        M=Mx*My
        for x in range(101):
            for y in range(101):
                for h in range(M):
                    for i in range(n):
                        if max(0,h-abs(lst[i][0]-x)-abs(lst[i][1]-y)) ==lst[i][2]:
                            if i ==n-1:
                                return x,y,h
                        else:
                            break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)

Submission status: Time Limit Exceeded

Solution code:
def abc(n:int,lst:list):
    l=list(map(lambda x:x[2],lst))
    if min(l)==0 and max(l)<201:
        for x in range(101):
            for y in range(101):
                for h in range(201):
                    for i in range(n):
                        if max(0,h-abs(lst[i][0]-x)-abs(lst[i][1]-y)) ==lst[i][2]:
                            if i ==n-1:
                                return x,y,h
                        else:
                            break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)

Submission status: Time Limit Exceeded

Solution code:
# C 未完
N = int(input())
def zeros(n): return [0 for i in range(n)]
x, y, h = zeros(N), zeros(N), zeros(N)
for i in range(N):
    x[i], y[i], h[i] = [int(x) for x in input().split()]
#print(x)#
#print(y)#
#print(h)#

found = False
for i in range(101):
    for j in range(101):
        for k in range(1,1001):
            #★if h[n] != max(k-abs(x[n]-i)-abs(y[n]-j), 0):break

            for n in range(N):
                #print(n)#
                if h[n] != max(k-abs(x[n]-i)-abs(y[n]-j), 0):break
            else: found = True
            if found: break
        if found: break
    if found: break
print('%d %d %d' % (i, j, k))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
X, Y, H_m = zip(*[tuple(map(int,input().split())) for _  in range(N)])
X, Y, H_m = map(np.array,[X,Y,H_m])

def height(X,Y,Cx,Cy,H):
    tmp = H - np.abs(X - Cx) - np.abs(Y - Cy)
    tmp[tmp <= 0] = 0
    return tmp

def solve(X,Y,H_m):
    for cx in range(0,101):
        for cy in range(0,101):
            H_c = 0
            while True:
                diff = H_m - height(X,Y,cx,cy,H_c)
                flgs_n = diff < 0
                flgs_e = diff == 0
                if all(flgs_e): return cx,cy,H_c
                if any(flgs_n): break
                H_c += 1
    return -1

print(" ".join(map(str,solve(X,Y,H_m))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
X, Y, H_m = zip(*[tuple(map(int,input().split())) for _  in range(N)])
X, Y, H_m = map(np.array,[X,Y,H_m])

def height(X,Y,Cx,Cy,H):
    tmp = H - np.abs(X - Cx) - np.abs(Y - Cy)
    tmp[tmp <= 0] = 0
    return tmp


def solve(X,Y,H_m):
    for cx in range(1,101):
        for cy in range(1,101):
            H_c = 0
            while True:
                diff = H_m - height(X,Y,cx,cy,H_c)
                flgs_n = diff < 0
                flgs_e = diff == 0
                if all(flgs_e): return cx,cy,H_c
                if any(flgs_n): break
                H_c += 1
    return -1

print(" ".join(map(str,solve(X,Y,H_m))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
X, Y, H_m = zip(*[tuple(map(int,input().split())) for _  in range(N)])
X, Y, H_m = map(np.array,[X,Y,H_m])

def height(X,Y,Cx,Cy,H):
    tmp = H - np.abs(X - Cx) - np.abs(Y - Cy)
    tmp[tmp <= 0] = 0
    return tmp

break_flg = False
for cx in range(1,101):
    for cy in range(1,101):
        H_c = 0
        while True:
            diff = H_m - height(X,Y,cx,cy,H_c)
            flgs_n = diff < 0
            flgs_e = diff == 0
            if all(flgs_e):
                break_flg = True
                break
            if any(flgs_n): break
            H_c += 1
        if break_flg:
            break
    if break_flg:
        break

print(" ".join(map(str,[cx,cy,H_c])))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N

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

for i in range(101):
    for j in range(101):
        for k in range(N):
            H = h[k] + abs(x[k]-i) + abs(y[k]-j)
            if H < 1:
                continue
            flg = True
            for l in range(N):
                if max (H-abs(x[l]-i)-abs(y[l]-j),0) != h[l] :
                    flg = False
                    break
            if flg:
                print("{} {} {}".format(i,j,H))
                exit()

Submission status: Time Limit Exceeded

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

i = 0
while 1:
    if P[0][2] > 0:
        break
    i += 1
x0, y0, h0 = P[i]
for cy in range(101):
    for cx in range(101):
        h = h0 + abs(cx - x0) + abs(cy - y0)
        for x, y, h1 in P:
            if h1 != max(h - abs(cx - x) - abs(cy - y), 0):
                break
        else:
            print(cx, cy, h)
            exit(0)
exit(1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

list = []
for i in range(0, N):
    x, y, h = [int(x) for x in input().split()]
    list.append((x, y, h))

'''
def calcCenterHeight(X, Y, Cx, Cy, Ch):
    return Ch + abs(X - Cx) + abs(Y - Cy)
'''


def calcCenterHeight(X, Y, Cx, Cy, Ch):
    s = set()
    H = Ch + abs(X - Cx) + abs(Y - Cy)
    s.add(H)
    if Ch == 0:
        for h in range(0, H):
            s.add(h)
    return s


from functools import reduce

for X in range(0, 101):
    for Y in range(0, 101):
        s = [calcCenterHeight(X, Y, Cx, Cy, Ch) for Cx, Cy, Ch in list]
        a = reduce(lambda a, b: a & b, s)
        # print(X, Y, s, a)
        if len(a) == 1:
            print(X, Y, a.pop())
            exit

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

list = []
for i in range(0, N):
    x, y, h = [int(x) for x in input().split()]
    list.append((x, y, h))

'''
def calcCenterHeight(X, Y, Cx, Cy, Ch):
    return Ch + abs(X - Cx) + abs(Y - Cy)
'''


def calcCenterHeight(X, Y, Cx, Cy, Ch):
    s = set()
    H = Ch + abs(X - Cx) + abs(Y - Cy)
    s.add(H)
    if Ch == 0:
        for h in range(0, H):
            s.add(h)
    return s


from functools import reduce

for X in range(0, 101):
    for Y in range(0, 101):
        s = [calcCenterHeight(X, Y, Cx, Cy, Ch) for Cx, Cy, Ch in list]
        a = reduce(lambda a, b: a & b, s)
        # print(X, Y, s, a)
        if len(a) == 1:
            print(X, Y, a.pop())

Submission status: Time Limit Exceeded

Solution code:
def main():
	n = int(input())

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

	for k in range(info[0][2], info[0][2] + 201):
		for i in range(101):
			for j in range(101):
				# [i][j]に高さkの頂上があった場合
				flg = 0
				for l in info:
					#print(l)
					deltax = abs(l[0] - i)
					deltay = abs(l[1] - j)
					guessh = max(k - deltax - deltay, 0)
					#print(guessh, k)
					if guessh != l[2]:
						flg = 1
						break
				#print("i,j,k,flg: ", i,j,k,flg)
				if flg == 0:
					print(i, j, k)
					return

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
hmin = INF
xyh = []
for i in range(N):
    x,y,h = inpl()
    hmin = min(h,hmin)
    xyh.append([x,y,h])

for H in range(hmin,hmin+210):
    for cx in range(101):
        for cy in range(101):
            flag= True
            for x,y,h in xyh:
                if max(H-abs(cx-x)-abs(cy-y),0) != h:
                    flag = False
                    break

            if flag:
                print(cx,cy,H)
                sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
n=int(input())
pos = list()
for i in range(n):
    xyh = list(map(int,input().split()))
    pos.append(xyh)
h_list = list()
for i in range(101):
    for j in range(101):
        for k in range(n):
            h = max(pos[k][2]+abs(pos[k][0]-i)+abs(pos[k][1]-j),0)
            h_list.append(h)
        if max(h_list)==min(h_list):
            print(i,j,h_list[0])
            sys.exit()

Submission status: Time Limit Exceeded

Solution code:
pattern = int(input())

xs = []
ys = []
hs = []

for _ in range(pattern):
    x, y, h = map(int, input().split(' '))
    xs.append(x)
    ys.append(y)
    hs.append(h)



correct = 0

max_h = max(hs) + 200

# 全探索
for Cx in range(101):
    for Cy in range(101):
        for H in range(max(hs), max_h):
            for x, y, h in zip(xs, ys, hs):
                if abs(x-Cx) + abs(y-Cy) == abs(h-H):
                    correct += 1
                    if correct == len(xs) and max(hs) <= H:
                        print(Cx, Cy, H)
                        exit()
                else:
                    correct = 0
                    continue

Submission status: Time Limit Exceeded

Solution code:
pattern = int(input())

xs = []
ys = []
hs = []

for _ in range(pattern):
    x, y, h = map(int, input().split(' '))
    xs.append(x)
    ys.append(y)
    hs.append(h)

correct = 0

max_h = max(hs) + 200

for Cx in range(101):
    for Cy in range(101):
        for H in range(max(hs), max_h):
            for x, y, h in zip(xs, ys, hs):
                if abs(x-Cx) + abs(y-Cy) == abs(h-H):
                    correct += 1
                    if correct == len(xs) and max(hs) <= H:
                        print(Cx, Cy, H)
                        quit()
                else:
                    correct = 0
                    continue

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
from operator import itemgetter
xyh = sorted(xyh, key = itemgetter(2))
for i in range(201):
    H = xyh[0][2] + i
    #print(H)
    for CX in range(101):
        for CY in range(101):
            ans = True
            for x, y, h in xyh:
                if h != max(H - abs(x - CX) - abs(y - CY), 0):
                    ans = False
                    break
            if ans:
                print(CX, CY, H)
                break
        if ans:
            break
    if ans:
        break

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import numpy as np
import collections
N = int(input())
arr = []
for n in range(N):
    arr.append(list(map(int,input().split())))
arr = np.array(arr)
x_min  = arr[:,0].min()
x_max = arr[:,0].max()
y_min = arr[:,1].min()
y_max =  arr[:,1].max()
mx = arr[:,2].max()
dx = x_max-x_min
dy = y_max-y_min
s = max(dx,dy)+1
for k in range(mx+s,mx-1,-1):
    for i in range(x_min,x_max+1):
        for j in range(y_min,y_max+1):
            for x,y,h in arr:
                if(max(k-abs(i-x)-abs(j-y),0)!=h):
                    break
            else:
                print (i,j,k)
                exit()

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import numpy as np
import collections
N = int(input())
arr = []
for n in range(N):
    arr.append(list(map(int,input().split())))
arr = np.array(arr)
x_min  = arr[:,0].min()
x_max = arr[:,0].max()
y_min = arr[:,1].min()
y_max =  arr[:,1].max()
mx = arr[:,2].max()
for k in range(mx+100,mx-1,-1):
    for i in range(x_min,x_max+1):
        for j in range(y_min,y_max+1):
            for x,y,h in arr:
                if(max(k-abs(i-x)-abs(j-y),0)!=h):
                    break
            else:
                print (i,j,k)
                exit()

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import numpy as np
import collections
N = int(input())
arr = []
for n in range(N):
    arr.append(list(map(int,input().split())))
arr = np.array(arr)
x_min  = arr[:,0].min()
x_max = arr[:,0].max()
y_min = arr[:,1].min()
y_max =  arr[:,1].max()
mx = arr[:,2].max()
for i in range(x_min,x_max+1):
    for j in range(y_min,y_max+1):
        for k in range(mx,mx+101):
            for x,y,h in arr:
                if(max(k-abs(i-x)-abs(j-y),0)!=h):
                    break
            else:
                print (i,j,k)
                exit()

Submission status: Time Limit Exceeded

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

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)
                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):
                    yield (xc, yc, hc2)

cand = set(get_cands(*XYH[0]))

for x, y, h in XYH[1:]:
    new_cand = set(get_cands(x, y, h))
    cand &= new_cand
print(*next(iter(cand)))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import numpy as np
import collections
N = int(input())
arr = []
for n in range(N):
    arr.append(list(map(int,input().split())))
arr = np.array(arr)

mx = arr[:,1:].max()
for i in range(101):
    for j in range(101):
        for k in range(mx,mx+199):
            flag = True
            for ls in arr:
                if(k-abs(i-ls[0])-abs(j-ls[1])!=ls[2]):
                    break
            else:
                print (i,j,k)
                exit()

Submission status: Time Limit Exceeded

Solution code:
pattern = int(input())

xs = []
ys = []
hs = []

for _ in range(pattern):
    x, y, h = map(int, input().split(' '))
    xs.append(x)
    ys.append(y)
    hs.append(h)

correct = 0

max_h = max(hs) + 200

for Cx in range(101):
    for Cy in range(101):
        for H in range(max(hs), max_h):
            for x, y, h in zip(xs, ys, hs):
                if abs(x-Cx) + abs(y-Cy) == abs(h-H):
                    correct += 1
                    if correct == len(xs) and max(hs) <= H:
                        print(Cx, Cy, H)
                        break
                else:
                    correct = 0
                    continue

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import numpy as np
import collections
N = int(input())
arr = []
for n in range(N):
    arr.append(list(map(int,input().split())))
arr = np.array(arr)

mx = arr[:,1:].max()
for i in range(101):
    for j in range(101):
        for k in range(mx,mx+199):
            flag = True
            for ls in arr:
                flag*=flag*(k-abs(i-ls[0])-abs(j-ls[1])==ls[2])
            if flag:
                print (i,j,k)
                exit()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def make_cands(x, y, h, i_min=0, i_max=3):
    cands = []
    for i in range(i_min, i_max + 1):
        if i == 0:
            cands.append([x, y, h])
        elif i == 1:
            cands.append([x + 1, y + 0, h + 1])
            cands.append([x + 0, y + 1, h + 1])
            cands.append([x - 1, y + 0, h + 1])
            cands.append([x + 0, y - 1, h + 1])
        else:
            cands.append([x + i, y + 0, h + i])
            cands.append([x + 0, y + i, h + i])
            cands.append([x - i, y + 0, h + i])
            cands.append([x + 0, y - i, h + i])
            for j in range(1, i):
                cands.append([x + j, y + (i-j), h + i])
                cands.append([x - j, y + (i-j), h + i])
                cands.append([x - j, y - (i-j), h + i])
                cands.append([x + j, y - (i-j), h + i])
    cands_ = []
    for i in range(len(cands)):
        if (cands[i][0] < 0) or (cands[i][0] > 100):
            continue
        if (cands[i][1] < 0) or (cands[i][1] > 100):
            continue
        if cands[i][2] <= 0:
            continue
        cands_.append(cands[i])
    s_cands = []
    for i in range(len(cands_)):
        s_cands.append(str(cands[i][0]) + ' ' + str(cands[i][1]) + ' ' + str(cands[i][2]))
    return s_cands

def intersect_cands(cands0, cands1):
    return list(set(cands0) & set(cands1))

#cands0 = make_cands(2, 3, 5, i_min=0, i_max=3)
#cands1 = make_cands(2, 1, 5, i_min=0, i_max=3)
#cands2 = make_cands(1, 2, 5, i_min=0, i_max=3)
#cands3 = make_cands(3, 2, 5, i_min=0, i_max=3)
#cands = list(set(cands0) & set(cands1) & set(cands2) & set(cands3))
#if len(cands) == 1:
#    print(cands[0])

N = int(input())
vec_x = []
vec_y = []
vec_h = []
for i in range(N):
    x, y, h = map(int, input().split())
    vec_x.append(x)
    vec_y.append(y)
    vec_h.append(h)

idx = np.argsort(vec_h)[::-1][:N]
vec_x = np.array(vec_x)[idx]
vec_y = np.array(vec_y)[idx]
vec_h = np.array(vec_h)[idx]

if True:
    cands = make_cands(vec_x[0], vec_y[0], vec_h[0], i_min=0, i_max=200)
    for i in range(1, N):
        for i_max in range(1, 200):
            cands_tmp = make_cands(vec_x[i], vec_y[i], vec_h[i], i_min=0, i_max=i_max)
            cands_ = list(set(cands) & set(cands_tmp))
            if len(cands_) < 1:
                continue
            cands = cands_
            break

    if len(cands) == 1:
        print(cands[0])
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
x = []
y = []
h = []
mode = 0
for i in range(n):
  _x,_y,_h = 0,0,0
  _x,_y,_h = map(int,input().split())
  x.append(_x)
  y.append(_y)
  h.append(_h)
  if _h == 0:
    mode += 1
if mode > 0:
  H = 1
  while True: 
    for i in range(101):
      Cx = i
      for j in range(101):
        Cy = j
        judge = 0
        for k in range(n):
          if h[k] != max(H - abs(x[k] - Cx) - abs(y[k] - Cy), 0):
            judge += 1
        if judge == 0:
          print(str(Cx) + ' ' + str(Cy) + ' ' + str(H))
          sys.exit()
  H += 1
else:
  for i in range(101):
      Cx = i
      for j in range(101):
        Cy = j
        judge = 0
        H = []
        for k in range(n):
          _H = h[k] + abs(x[k] - Cx) + abs(y[k] - Cy)
          H.append(_H)
        for k in range(1,n):
          if H[0] != H[k]:
            judge += 1
        if judge == 0:
          print(str(Cx) + ' ' + str(Cy) + ' ' + str(H[0]))
          sys.exit()

Submission status: Time Limit Exceeded

Solution code:
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)


cxyl = []
for i in range(101):
    for j in range(101):
        cxyl.append((i,j))
cxy = set(cxyl)
hd = {}
hzero = []
for i in range(n):
    for c in list(cxy):
        H = abs(x[i]-c[0]) + abs(y[i]-c[1]) + h[i]
        if h[i] == 0:
            hzero.append((x[i],y[i]))
            if 1 > H:
                cxy.remove(c)
                continue
        else:
            if c in hd:
                if hd[c] != H:
                    cxy.remove(c)
                    continue
            else:
                hd[c] = H

for xy in hzero:
    xi = xy[0]
    yi = xy[1]
    for c in list(cxy):
        H = abs(xi-c[0]) + abs(yi-c[1])
        if hd[c] - H > 0:
            cxy.remove(c)

ret = cxy.pop()
print(str(ret[0]) + ' ' + str(ret[1]) + ' ' + str(hd[ret]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
numss = [[int(i) for i in input().split()] for i in range(n)]

def h(x,y,h,cx,cy):
    return h+abs(x-cx)+abs(y-cy)
def hc(x,y,cx,cy,H):
    return max(H-abs(x-cx)-abs(y-cy),0)
def check(cx,cy,H):
    flag = True
    for nums in numss:
        if hc(nums[0],nums[1],cx,cy,H) == nums[2]:
            pass
        else:
            flag=False
            break
    return flag
ans=[]
for cx in range(0,101):
    for cy in range(0,101):
        for nums in numss:
            H=h(nums[0],nums[1],nums[2],cx,cy)
            if check(cx,cy,H):
                ans.append(cx)
                ans.append(cy)
                ans.append(H)
                break
if len(ans)==0:
    print("0 0 0")
else:
    print(ans[0],ans[1],ans[2])

Submission status: Time Limit Exceeded

Solution code:
pattern = int(input())

xs = []
ys = []
hs = []


for _ in range(pattern):
    x, y , h = map(int,input().split(' '))
    xs.append(x)
    ys.append(y)
    hs.append(h)

correct = 0

max_h = max(hs) + 120

for Cx in range(101):
    for Cy in range(101):
        for H in range(1, max_h):
            for x, y, h in zip(xs, ys, hs):
                if abs(x-Cx) + abs(y-Cy) == abs(h-H):
                    correct += 1
                    if correct == len(xs) and max(hs) <= H:
                        print(Cx, Cy, H)
                else:
                    correct = 0
                    continue

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def make_cands(x, y, h, i_min=0, i_max=3):
    cands = []
    for i in range(i_min, i_max + 1):
        if i == 0:
            cands.append([x, y, h])
        elif i == 1:
            cands.append([x + 1, y + 0, h + 1])
            cands.append([x + 0, y + 1, h + 1])
            cands.append([x - 1, y + 0, h + 1])
            cands.append([x + 0, y - 1, h + 1])
        else:
            cands.append([x + i, y + 0, h + i])
            cands.append([x + 0, y + i, h + i])
            cands.append([x - i, y + 0, h + i])
            cands.append([x + 0, y - i, h + i])
            for j in range(1, i):
                cands.append([x + j, y + (i-j), h + i])
                cands.append([x - j, y + (i-j), h + i])
                cands.append([x - j, y - (i-j), h + i])
                cands.append([x + j, y - (i-j), h + i])
    cands_ = []
    for i in range(len(cands)):
        if (cands[i][0] < 0) or (cands[i][0] > 100):
            continue
        if (cands[i][1] < 0) or (cands[i][1] > 100):
            continue
        if cands[i][2] <= 0:
            continue
        cands_.append(cands[i])
    s_cands = []
    for i in range(len(cands_)):
        s_cands.append(str(cands[i][0]) + ' ' + str(cands[i][1]) + ' ' + str(cands[i][2]))
    return s_cands

def intersect_cands(cands0, cands1):
    return list(set(cands0) & set(cands1))

#cands0 = make_cands(2, 3, 5, i_min=0, i_max=3)
#cands1 = make_cands(2, 1, 5, i_min=0, i_max=3)
#cands2 = make_cands(1, 2, 5, i_min=0, i_max=3)
#cands3 = make_cands(3, 2, 5, i_min=0, i_max=3)
#cands = list(set(cands0) & set(cands1) & set(cands2) & set(cands3))
#if len(cands) == 1:
#    print(cands[0])

N = int(input())
vec_x = []
vec_y = []
vec_h = []
for i in range(N):
    x, y, h = map(int, input().split())
    vec_x.append(x)
    vec_y.append(y)
    vec_h.append(h)

idx = np.argsort(vec_h)[::-1][:N]
vec_x = np.array(vec_x)[idx]
vec_y = np.array(vec_y)[idx]
vec_h = np.array(vec_h)[idx]

for i_max in range(1, 100):
    cands = make_cands(vec_x[0], vec_y[0], vec_h[0], i_min=0, i_max=i_max)
    for i in range(1, N):
        cands_tmp = make_cands(vec_x[i], vec_y[i], vec_h[i], i_min=0, i_max=i_max)
        cands = list(set(cands) & set(cands_tmp))
        if len(cands) < 1:
            break
    if len(cands) == 1:
        print(cands[0])
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
x = []
y = []
h = []
for i in range(n):
  _x,_y,_h = 0,0,0
  _x,_y,_h = map(int,input().split())
  x.append(_x)
  y.append(_y)
  h.append(_h)
H = 1
while True: 
  for i in range(101):
    Cx = i
    for j in range(101):
      Cy = j
      judge = 0
      for k in range(n):
        if h[k] != max(H - abs(x[k] - Cx) - abs(y[k] - Cy), 0):
          judge += 1
      if judge == 0:
        print(str(Cx) + ' ' + str(Cy) + ' ' + str(H))
        sys.exit()
  H += 1

Submission status: Time Limit Exceeded

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

for cx in range(101):
  for cy in range(101):
    for i in range(n):
      b=h[i]+abs(x[i]-cx)+abs(y[i]-cy)
      if i==0:
        if h[i]:
          s=set()
          s.add(b)
        else:
          s={i for i in range(b+1)}
      else:
        if not s:break
        if h[i]:
          s&=set([b])
        else:
          s&=set(range(b+1))
    if s:
      print(cx,cy,s.pop())
      exit()

Submission status: Time Limit Exceeded

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

for cx in range(101):
  for cy in range(101):
    for i in range(n):
      b=h[i]+abs(x[i]-cx)+abs(y[i]-cy)
      if i==0:
        if h[i]:
          s=set()
          s.add(b)
        else:
          s={i for i in range(b+1)}
      else:
        if h[i]:
          s&=set([b])
        else:
          s&=set(range(b+1))
    if s:print(cx,cy,s.pop())

Submission status: Time Limit Exceeded

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

for cx in range(101):
  for cy in range(101):
    for i in range(n):
      b=h[i]+abs(x[i]-cx)+abs(y[i]-cy)
      if i==0:
        if h[i]:
          s=set()
          s.add(b)
        else:
          s={i for i in range(b+1)}
      else:
        if h[i]:
          s&=set([b])
        else:
          s&={i for i in range(b+1)}
    if s:print(cx,cy,s.pop())

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = []
y = []
h = []
for _ in range(N):
    xx,yy,hh = map(int,input().split())
    x.append(xx)
    y.append(yy)
    h.append(hh)
cm = 100
def height(cx,x,cy,y,h):
    return(max(0,h-abs(cx-x)-abs(cy-y)))
def judge(cx,cy,hc):
    for i in range(N):
        hcand = height(cx,x[i],cy,y[i],hc) 
        if hcand < h[i]:
            return(-1)
        if hcand > h[i]:
            return(1)
    return(0)
        
    
for cx in range(cm+1):
    for cy in range(cm+1):
        left = -1
        right = 1000000001
        while right > left:
            mid = (right+left)//2
            j = judge(cx,cy,mid) 
            if j == 0:
                print(cx,cy,mid)
                exit()
            elif j == 1:
                right = mid
            else:
                left = mid

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 = max(hlist)
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