Problem: 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.

Submission attempts (in order):
import itertools
N=int(input())
l=[]

M=max(item[2] for item in l)
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))

for A,B in itertools.combinations(range(N),2):
  
  if len(s)==1:
    break
  t=[]
  
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    
    if l[B][2]==0:
      
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    
    
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>=M and abs(X-l[B][0])+abs(Y-l[B][1])>=M:
        t.append((X,Y))
  s=t[:]

a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)


import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=[]
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]!=0:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    t=[:]
  s=t[:]
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=set(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=set()
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.add((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.add((X,Y))
  elif l[A][2]!=0:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.add((X,Y))
  else:
    t=s.copy()
    if (l[A][0],l[A][1]) in t:
      t.remove((l[A][0],l[A][1]))
    if (l[B][0],l[B][1]) in t:
      t.remove((l[B][0],l[B][1]))    

  s=t.copy()
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

import itertools
N=int(input())
l=[]
for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
s=list(itertools.product(range(0,101),repeat=2))
for A,B in itertools.combinations(range(N),2):
  if len(s)==1:
    break
  t=[]
  if l[A][2]>l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])<abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]<l[B][2]:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  elif l[A][2]!=0:
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]):
        t.append((X,Y))
  else:
    for X,Y in s:
      if (X,Y)!=(l[A][0],l[A][1]) and (X,Y)!=(l[B][0],l[B][1]):
        t.append((X,Y))
a,b=s[0][0],s[0][1]
h=abs(a-l[0][0])+abs(b-l[0][1])+l[0][2]
print(a,b,h)

import itertools
N=int(input())
l=[]

for i in range(N):
  x,y,h=map(int,input().split())
  l.append([x,y,h])
M=max(item[2] for item in l)
s=list(itertools.product(range(0,101),repeat=2))

for A,B in itertools.combinations(range(N),2):
  
  if len(s)==1:
    break
  t=[]
  
  if l[A][2]<l[B][2]:
    A,B=B,A
  if l[A][2]>l[B][2]:
    
    if l[B][2]==0:
      
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap<=abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
    else:
      
      gap=l[A][2]-l[B][2]
      for X,Y in s:
        if abs(X-l[A][0])+abs(Y-l[A][1])+gap==abs(X-l[B][0])+abs(Y-l[B][1]):
          t.append((X,Y))
  
  elif l[A][2]!=0:
    
    
    for X,Y in s:
      MM=max(1,M-l[A][2])
      if abs(X-l[A][0])+abs(Y-l[A][1])==abs(X-l[B][0])+abs(Y-l[B][1]) and abs(X-l[A][0])+abs(Y-l[A][1])>=MM and abs(X-l[B][0])+abs(Y-l[B][1])>=MM:
        t.append((X,Y))
  else:
    
    
    for X,Y in s:
      if abs(X-l[A][0])+abs(Y-l[A][1])>=M and abs(X-l[B][0])+abs(Y-l[B][1])>=M:
        t.append((X,Y))
  s=t[:]

a,b=s[0][0],s[0][1]
i=0
while l[i][2]==0:
  i+=1

h=abs(a-l[i][0])+abs(b-l[i][1])+l[i][2]
print(a,b,h)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted