Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created December 2, 2023 07:41
Show Gist options
  • Save maehrm/5d33687cdbcbf2b1b9ef32cb0e6cc41d to your computer and use it in GitHub Desktop.
Save maehrm/5d33687cdbcbf2b1b9ef32cb0e6cc41d to your computer and use it in GitHub Desktop.
036 - Max Manhattan Distance(★5) https://atcoder.jp/contests/typical90/tasks/typical90_aj
N, Q = map(int, input().split())
u, v = [], []
for _ in range(N):
x, y = map(int, input().split())
u.append(x + y)
v.append(x - y)
u_max, u_min = max(u), min(u)
v_max, v_min = max(v), min(v)
for _ in range(Q):
q = int(input()) - 1
ans = max(
abs(u[q] - u_max), abs(u[q] - u_min), abs(v[q] - v_max), abs(v[q] - v_min)
)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment