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 bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    # maxの逆演算のため、hが0なものとそうでないものに分類
    xyh_0 = []
    xyh_not0 = []
    for _ in range(N):
        xyh = LI()
        if xyh[2] == 0:
            xyh_0.append(xyh)
        else:
            xyh_not0.append(xyh)

    for cx, cy in itertools.product(range(101), range(101)):
        H = []
        for x, y, h in xyh_not0:
            H.append(h + abs(x - cx) + abs(y - cy))
        # hが0でないものでOKだったら、hが0のもので辻褄が会うかどうか見る
        if len(set(H)) == 1:
            is_ok = True
            for x, y, h in xyh_0:
                if max(H[0] - abs(x - cx) - abs(y - cy), 0) != 0:
                    is_ok = False
            if is_ok:
                ans = (cx, cy, H[0])

    print(*ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())

xy = [[-1 for i in range(101)] for j in range(101)]

x = []
y = []
h = []
for i in range(n):
  xx, yy, hh = map(int, input().split())
  x.append(xx)
  y.append(yy)
  h.append(hh)
  if hh > 0:
    x0, y0, h0, = xx, yy, hh

for i in range(101):
  for j in range(101):
    flg = 0
    tmp = h0 + abs(x0-i) + abs(y0-j)
    for k in range(n):
      if h[k] != max(tmp - abs(x[k]-i) - abs(y[k]-j),0):
        flg = 1
        break
    if flg == 0:
      print (i,j,tmp)
      exit()

Submission status: Accepted

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

# C - Pyramid /
# 実行時間制限: 3 sec / メモリ制限: 1024 MB
# 配点: 300点

# 問題文
# 古代すぬけ国では, AtCoder 社長「高橋君」の権威を高めるために, ピラミッドが建てられていた.
# ピラミッドには 中心座標 (CX,CY)と 高さ H が定まっており, 座標 (X,Y) の高度は max(H−|X−CX|−|Y−CY|,0)であった.
# 探検家の青木君は, このピラミッドの中心座標と高さを求めるために調査を行った. その結果, 次のような情報が得られた.
#     CX,CYは 0 以上 100 以下の整数で, H は 1以上の整数であった.
#     上記と別に N個の情報が得られた. そのうち i 個目の情報は, 「座標 (xi,yi) の高度は hiである」
# この情報は, ピラミッドの中心座標と高さを特定するのに十分であった. 情報を手掛かりに, これらの値を求めなさい.

# 制約
#     Nは 1 以上 100以下の整数
#     xi, yi は 0 以上 100以下の整数
#     hiは 0 以上 109以下の整数
#     N個の座標 (x1,y1),(x2,y2),(x3,y3),...,(xN,yN)はすべて異なる
#     ピラミッドの中心座標と高さをちょうど 1つに特定することができる

# 入力
# 入力は以下の形式で標準入力から与えられる.
# N
# x1 y1 h1
# x2 y2 h2
# x3 y3 h3
# :
# xN yN hN

# 出力
# 特定した中心座標と高さを表す整数 CX,CY,Hを空白区切りで, 1 行に出力しなさい.

# 入力例 1
# 4
# 2 3 5
# 2 1 5
# 1 2 5
# 3 2 5

# 出力例 1
# 2 2 6

# この場合, 中心座標は (2,2), 高さは 6と特定することができる.

# 入力例 2
# 2
# 0 0 100
# 1 1 98

# 出力例 2
# 0 0 100

# この場合, 中心座標は (0,0), 高さは 100 と特定することができる.
# CX,CY が 0 以上 100以下の整数であると分かっていることに注意せよ.

# 入力例 3
# 3
# 99 1 191
# 100 1 192
# 99 0 192

# 出力例 3
# 100 0 193

# この場合, 中心座標は (100,0), 高さは 193 と特定することができる.


def calculation(lines):
    N = int(lines[0])
    # N, T = list(map(int, lines[0].split()))
    # n = lines[0]

    points = list()
    highest = 0
    for i in range(1, N+1):
        point = list(map(int, lines[i].split()))
        # print(point)
        points.append(point)
        if highest < point[2]:
            highest = point[2]
        # print(f'points=[{points}]')

    for x in range(101):
        for y in range(101):
            for h in range(highest, highest+200):
                # print(f'x=[{x}], y=[{y}], h=[{h}]')
                flag = True
                for point in points:
                    # print(f'point=[{point}]')
                    calc_h = max(h - abs(point[0]-x) - abs(point[1]-y), 0)
                    if point[2] != calc_h:
                        flag = False
                        break
                if flag:
                    result = str(x) + ' ' + str(y) + ' ' + str(h)
                    return [result]


# 引数を取得
def get_input_lines():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4', '2 3 5', '2 1 5', '1 2 5', '3 2 5']
        lines_export = ['2 2 6']
    if pattern == 2:
        lines_input = ['2', '0 0 100', '1 1 98']
        lines_export = ['0 0 100']
    if pattern == 3:
        lines_input = ['3', '99 1 191', '100 1 192', '99 0 192']
        lines_export = ['100 0 193']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import product

input = sys.stdin.readline


def main():
    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())

    for Cx, Cy in product(range(101), repeat=2):
        Ch = set()
        Ch_upper = float("inf")
        for x, y, h in zip(X, Y, H):
            a = abs(x - Cx) + abs(y - Cy)
            if h == 0:
                Ch_upper = min(Ch_upper, a)
            else:
                Ch.add(h + a)
        if len(Ch) != 1:
            continue
        else:
            Ch = Ch.pop()
            if Ch <= Ch_upper:
                ans = f"{Cx} {Cy} {Ch}"
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(101):
    for j in range(101):
        h = l[0][2] + abs(i - l[0][0]) + abs(j - l[0][1])
        for k in range(N):
            tmp = max(h - abs(i - l[k][0]) - abs(j - l[k][1]), 0)
            if tmp != l[k][2]:
                break
            elif k == N-1:
                X = i
                Y = j
                H = h
print(X,Y,H)

Submission status: Accepted

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

for x in range(101):
    for y in range(101):
        hmax = XYH[0][2] + abs(x-XYH[0][0]) + abs(y-XYH[0][1])
        for i in range(n):
            if max(hmax-abs(x-XYH[i][0])-abs(y-XYH[i][1]), 0) != XYH[i][2]:
                break
            if i==n-1:
                print(x, y, hmax)
                exit()

Submission status: Accepted

Solution code:
n = int(input())
coords = [tuple(map(int, input().split())) for i in range(n)]
for xt, yt, ht in coords:
    if ht != 0:
        break
x, y, h = -1, -1, -1
for px in range(101):
    for py in range(101):
        flag = True
        htmp = ht + abs(px-xt) + abs(py-yt)
        dxdy = [(abs(px-x1)+abs(py-y1), htmp-h1) for x1, y1, h1 in coords]
        dxdy.sort()
        for i in range(n-1):
            if dxdy[i][0] < dxdy[i+1][0] and dxdy[i][1] > dxdy[i+1][1]:
                flag = False
                break
        for x1, y1, h1 in coords:
            #print (px, py, htmp, x1, y1, h1)
            if h1 == 0:
                continue
            if abs(htmp-h1) != abs(px-x1) + abs(py-y1):
                flag = False
                break
        if flag:
            if htmp > h:
                h = htmp
                x = px
                y = py
print (x, y, h)

Submission status: Accepted

Solution code:
N = int(input())

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

# このセットから中心座標と高さは絞り込める


def compute_diff_from_top(x, y, cx, cy):
    # -4 + -77
    return ((-1 * abs(x - cx)) + (-1 * abs(y - cy)))


ans = 0
ans_x = None
ans_y = None
for i in range(101):
    for j in range(101):
        nums = []
        for high_set in high_sets:
            # i == 55 j == 80
            # high_set_x = 59 high_set_y = 3
            # high_set[2] == 0の時は、区別が必要。
            num = high_set[2] + (-1 * compute_diff_from_top(i, j, high_set[0], high_set[1]))
            if high_set[2] == 0:
                nums.append(-1)
            else:
                nums.append(num)
        # if i == 32:
        #     print(i, j, nums)
        if len(set(nums)) == 1:
            ans_x, ans_y = i, j
            ans = nums.pop()
        else:
            if len(set(nums)) == 2 and -1 in nums:
                nums = set(nums)
                nums.remove(-1)
                top = nums.pop()
                check = True
                for high_set in high_sets:
                    # if i == 32 and j == 68:
                    #     print(top, compute_diff_from_top(i, j, high_set[0], high_set[1]))
                    if max(0, top + compute_diff_from_top(i, j, high_set[0], high_set[1])) != high_set[2]:
                        check = False
                if check:
                    ans_x, ans_y = i, j
                    ans = top


print(ans_x, ans_y, ans)
# 55 80 79

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
h_list =[0]*N

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

from bisect import bisect_right
xyh.sort(key =lambda x:x[2])
h_list.sort()
ind =bisect_right(h_list,0)
from collections import defaultdict
H =defaultdict(set)

for x,y,h in xyh[ind:]:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
if len(xyh[ind:]) ==1:
    print(*xyh[-1])
else:
    for k,v in H.items():
    
        if len(v)==1:
            vv =v.pop()
            if 0 <= vv :
                print(*k,vv)
            elif vv <0:
                print(*k,0)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
xyh = [lr() for i in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)
for i in range(0,101):
    for j in range(0,101):
        H = abs(xyh[0][0]-i)+abs(xyh[0][1]-j)+xyh[0][2]
        flag = True
        for k in range(1,n):
            h = abs(xyh[k][0]-i)+abs(xyh[k][1]-j)+xyh[k][2]
            if not ((h>H and xyh[k][2]==0) or h==H):
                flag = False
                break
        if flag:
            print(i,j,H)
            sys.exit()

Submission status: Accepted

Solution code:
#c
N=int(input())
XYH = [None]*N
for i in range(N):
    XYH[i] = list(map(int,input().split()))

for cx in range(101):
    for cy in range(101):
        found=False
        for i in range(N):
            d = abs(XYH[i][0]-cx)+abs(XYH[i][1]-cy)
            if XYH[i][2]>0 and not found:
                h = XYH[i][2]+d
                break
        for i in range(N):
            d = abs(XYH[i][0]-cx)+abs(XYH[i][1]-cy)
            if XYH[i][2]!= max(0,h-d):
                break
        else:
            print(cx,cy,h)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)

# print(xyh)
ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = 0
        flag = True
        for i, (x, y, h) in enumerate(xyh):
            if i == 0:
                H = h + abs(x - c_x) + abs(y - c_y)
            if h != max(H - abs(x - c_x) - abs(y - c_y), 0):
            # if H != max(h + abs(x - c_x) + abs(y - c_y), 0):
                flag = False
        if flag:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Submission status: Accepted

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

ans = False
for cy in range(101):
    for cx in range(101):
        x0, y0, h0 = xyh[0]
        H = abs(x0-cx) + abs(y0-cy) + h0
        # 全てのクエリについて高さを計算する
        for x, y, h in xyh[1:]:
            hh = max(H-abs(x-cx)-abs(y-cy), 0)
            if h != hh:
                break
        else:
            # 回り切ったら答え
            ans = True
            print(cx, cy, H)
            break
        if ans:
            break
    if ans:
        break

Submission status: Accepted

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

for xi in range(0, 101):
    for yi in range(0, 101):
        tmpH = 0
        for k in range(N):
            x,y,h = XYH_list[k]
            if k == 0:
                tmpH =h + abs(x - xi) + abs(y - yi)
            if h == max((tmpH - abs(x - xi) - abs(y - yi)), 0):
                if k == N - 1:
                    ans = [str(xi), str(yi), str(tmpH)]
                continue
            else:
                break
print(' '.join(ans))

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l=[]
for i in range(n):
  x,y,h=nii()
  l.append([x,y,h])
  if h!=0:
    ini_x=x
    ini_y=y
    ini_h=h

for tx in range(101):
  for ty in range(101):
    n_h=abs(tx-ini_x)+abs(ty-ini_y)+ini_h
    for x,y,h in l:
      t_h=max(n_h-(abs(tx-x)+abs(ty-y)),0)
      if h!=t_h:
        break
    else:
      print(tx,ty,n_h)
      exit()

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    XYH = [NLI() for _ in range(N)]
    XYH.sort(key= lambda x: x[2], reverse=True)
    H = 10**10
    for cx in range(101):
        for cy in range(101):
            is_badc = False
            for i, xyh in enumerate(XYH):
                x, y, h = xyh
                if i == 0:
                    H = h + abs(cx - x) + abs(cy - y)
                else:
                    if max(H - abs(cx-x) - abs(cy-y), 0) != h:
                        is_badc = True

            if not is_badc:
                print(cx, cy, H)
                exit()



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    X, Y, H = [], [], []
    for i in range(n):
        x, y, h = map(int, input().split())
        X.append(x), Y.append(y), H.append(h)

    for cx in range(101):
        for cy in range(101):
            res = []
            for x, y, h in zip(X, Y, H):
                if h == 0:
                    continue
                hh = h + abs(x - cx) + abs(y - cy)
                res.append(hh)
            if len(set(res)) == 1:
                flg = True
                for x, y, h in zip(X, Y, H):
                    if h != max(res[0] - abs(x - cx) - abs(y - cy), 0):
                        flg = False
                if flg:
                    print(cx, cy, res[0])

solve()

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh=sorted(xyh,key=lambda x:x[2])
for cx in range(101):
    for cy in range(101):
        h_a=h_b=10**10
        minh=10**10
        for i in range(n):
            x,y,h=xyh[i]
            if h!=0:
                h_a=h+abs(cx-x)+abs(cy-y)
                if h_a>minh:
                  break
                elif h_b!=10**10 and h_a!=h_b:
                    break
                else:
                    h_b=h_a
            else:
                minh=min(minh,abs(cx-x)+abs(cy-y))
                if minh==0:
                  break
        else:
            if minh==1 and h_a==10**10:
              print(cx,cy,1)
              exit()
            else:
                print(cx,cy,h_a)
                exit()

Submission status: Accepted

Solution code:
n=int(input())
x=[]
y=[]
h=[]
for i in range(n):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
  if c!=0:q=[a,b,c]
for i in range(101):
  for j in range(101):
    H=q[2]+abs(q[0]-i)+abs(q[1]-j)
    for a,b,c in zip(x,y,h):
      if c!=max(H-abs(a-i)-abs(b-j),0):break
    else:
      print(i,j,H)
      exit()

Submission status: Accepted

Solution code:
n=int(input())
lst=[None]*n
for i in range(n):
    a,b,c=map(int,input().split())
    lst[i]=[a,b,c]
lst=sorted(lst,key=lambda x:x[2],reverse=True)
for i in range(101):
    for j in range(101):
        switch=0
        x,y,z=lst[0]
        height=z+abs(i-x)+abs(j-y)
        for k in range(1,n):
            x,y,z=lst[k]
            if z==0:
                if abs(i-x)+abs(j-y)<height:
                    switch=1
                    break
            elif abs(i-x)+abs(j-y)+z!=height:
                switch=1
                break
        if switch==0:
            print(i,j,height)

Submission status: Accepted

Solution code:
n=int(input())
query=[]
for _ in range(n):
    a,b,c=map(int,input().split())
    query.append((a,b,c))
query=sorted(query, key=lambda x:x[2], reverse=True)

for cx in range(101):
  for cy in range(101):
      h=None
      flg=True
      for q in query:
        if h==None:
          h=q[2]+abs(cx-q[0])+abs(cy-q[1])
        elif q[2]!=0 and h!=q[2]+abs(cx-q[0])+abs(cy-q[1]):
          flg=False
          break
        elif q[2]==0 and h-abs(cx-q[0])-abs(cy-q[1])>0:
          flg=False
          break
      if flg: 
        print(cx,cy,h)
        exit()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

if N==1:
    print(xyh[0],xyh[1],xyh[2])
else:
    for cx in range(101):
        for cy in range(101):
            flag = 0
            dx = abs(cx - xyh[0][0])
            dy = abs(cy - xyh[0][1])
            hmax = xyh[0][2]+dx+dy
            for i in range(1,N):
                if max(hmax -( abs(cx - xyh[i][0])+abs(cy - xyh[i][1])),0) !=  xyh[i][2]:
                    flag = 1
                    break
            if flag == 0:
                print(cx,cy,hmax)
                exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

for cx in range(101):
    for cy in range(101):
        candidates = set()
        for x, y, h in A:
            h += abs(x - cx) + abs(y - cy)
            candidates.add(h)
        for H in candidates:
            for x, y, h in A:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print(cx, cy, H)
                exit()

Submission status: Accepted

Solution code:
n = int(input())

xyh = [list(map(int, input().split())) for i in range(n)]
if xyh[0][2]:
    x,y,h = xyh[0]
if xyh[1][2]:
    x,y,h = xyh[1]
if xyh[-1][2]:
    x,y,h = xyh[-1]
for i in range(101):
    for j in range(101):
        k = h + abs(i - x) + abs(j - y)
        if all(h == max(k - abs(i - x) - abs(j - y), 0) for x, y, h in xyh):
            print(i, j, k)

Submission status: Accepted

Solution code:
import collections
n = int(raw_input())
pts = [map(int , raw_input().split()) for _ in range(n)]

def f(pts):
	for cx,cy in [(ii,jj) for ii in range(100+1) for jj in range(100+1)]:	
		H = min([abs(cx - x) + abs(cy - y) for x,y,h in pts if h == 0] or [+float('inf')])
		
		cc = collections.Counter()
		for x,y,h in pts:
			q = abs(cx - x) + abs(cy - y)
			if h > 0:
				Y = h + q
				if 1<=Y <= H:
					cc[Y]+=1
				else:
					cc[-1] += 1
		if len(cc) == 1:
			for k in cc:
				if 1<=k <= H:
					return k,cx,cy

h,x,y = f(pts)

print x,y,h

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
    xyh = list(map(int, input().split()))
    l.append(xyh)
    if xyh[2]:
        x, y, h = xyh
for i in range(101):
    for j in range(101):
        k = h + abs(i - x) + abs(j - y)
        if all(h == max(k - abs(i - x) - abs(j - y), 0) for x, y, h in l):
            print(i, j, k)

Submission status: Accepted

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

h_range = {}
for cx in range(0, 101):
    for cy in range(0, 101):
        h_range[(cx, cy)] = [1, 10000000000]

for i in range(n):
    for (cx, cy) in h_range.keys():
        ch_max = h[i] + (abs(cx - x[i]) + abs(cy - y[i]))
        if h[i] == 0:
            ch_min = 0
        else:
            ch_min = ch_max
        ch_range = h_range[(cx, cy)]
        h_range[(cx, cy)] = [max(ch_min, ch_range[0]), min(ch_max, ch_range[1])]

for (cx, cy) in h_range.keys():
    ch_range = h_range[(cx, cy)]
    if ch_range[0] <= ch_range[1]:
        for ch in range(ch_range[0], ch_range[1] + 1):
            print('{} {} {}'.format(cx, cy, ch))

Submission status: Accepted

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

def chech(Cx,Cy,x,y,h):
    if h > 0:
        H = h + abs(x-Cx) + abs(y-Cy)
        c_list.append(H)
    return 
    
for Cx in range(101):
    for Cy in range(101):
        c_list=[]
        c_list_zero=[]
        for i in info:
            x,y,h=i
            c_=chech(Cx,Cy,x,y,h)

        if len(set(c_list))==1:
            check_zero=True
            for i in info:
                x,y,h=i
                H = c_list[0]
                h_=max(H - (abs(x-Cx) + abs(y-Cy)),0)
                if h_ != h:
                    check_zero=False
                
            if check_zero==True:
                print(Cx,Cy,c_list[0])

Submission status: Accepted

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

for x, y, h in xyh:
    if h > 0:
        x0, y0, h0 = x, y, h
        break

ans = [None] * 3
for cx in range(101):
    for cy in range(101):
        top = h0 + abs(x0 - cx) + abs(y0 - cy)
        bl = True
        for x, y, h in xyh[1:]:
            h_calc = max(top - abs(x - cx) - abs(y - cy), 0)
            if h_calc != h:
                bl = False
                break

        if bl:
            ans = [cx, cy, top]

print(*ans)

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 = [None] * 3
for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = xyh[0]
        top = h0 + abs(x0 - cx) + abs(y0 - cy)
        bl = True
        for x, y, h in xyh[1:]:
            h_calc = max(top - abs(x - cx) - abs(y - cy), 0)
            if h_calc != h:
                bl = False
                break

        if bl:
            ans = [cx, cy, top]

print(*ans)

Submission status: Accepted

Solution code:
N = int(input())

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


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

        prev = None
        flg = False
        zeros = []
        for x, y, h in XYH:
            if h == 0:
                zeros.append((x, y, h))
                continue

            cur_h = h + abs(x - cx) + abs(y - cy)

            if prev is not None:
                if prev != cur_h:
                    flg = True
                    break

            prev = cur_h

        if not flg:
            for x, y, h in zeros:
                if max(0, cur_h - abs(x - cx) - abs(y - cy)) != 0:
                    flg = True
                    break

            if not flg:
                print(cx, cy, cur_h)
                exit()

Submission status: Accepted

Solution code:
abalable_H = []
N = int(input())
x = []
y = []
h = []
first =-1
for i in range(0,N,1):
    tmpx,tmpy,tmph = map(int,input().split())
    x.append(tmpx)
    y.append(tmpy)
    h.append(tmph)
    if tmph !=0 and first == -1:
        first = i

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