Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 9, 2018 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/2525c85b63b6cf0eb5ef926c792ce6b3 to your computer and use it in GitHub Desktop.
Save whatalnk/2525c85b63b6cf0eb5ef926c792ce6b3 to your computer and use it in GitHub Desktop.
AtCoder ABC #112 C
n = gets.chomp.to_i
ax = []
ay = []
ah = []
gx, gy, gh = -1, -1, -1
n.times do
x, y, h = gets.chomp.split(" ").map(&:to_i)
ax << x
ay << y
ah << h
gx, gy, gh = x, y, h if h > 0
end
ans = []
0.upto(100) do |cx|
0.upto(100) do |cy|
ch = gh + (gx - cx).abs + (gy - cy).abs
ch = [ch, 0].max
flag = true
n.times do |i|
x = ax[i]
y = ay[i]
h = ah[i]
hh = ch - (x - cx).abs - (y - cy).abs
hh = [hh, 0].max
if h != hh
flag = false
end
end
if flag
ans << [cx, cy, ch]
end
end
end
if ans.length == 1
puts ans[0].join(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment