Problem:


Score : 500 points

Problem Statement

There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate.
What is the maximum possible Manhattan distance between two distinct points?

Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq x_i,y_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the answer.

Sample Input 1

3
1 1
2 4
3 2

Sample Output 1

4

The Manhattan distance between the first point and the second point is |1-2|+|1-4|=4, which is maximum possible.

Sample Input 2

2
1 1
1 1

Sample Output 2

0



Sample input:
3
1 1
2 4
3 2


Sample output:
4

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
a=[]
b=[]
c=[]
d=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append(x-y)
    b.append(x+y)
a=sorted(a)
b=sorted(b)
ans=[a[-1]-a[0],b[-1]-b[0]]
print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
for c in range(n):
    x,y=map(int,input().split())
    a.append(x+y)
    b.append(x-y)
s1=max(a)-min(a)
s2=max(b)-min(b)
print(max(s1,s2))

Submission status: Accepted

Solution code:
n = int(input())

min_x = 10 ** 9
max_x = -(10 ** 9)
min_y = 10 ** 9
max_y = -(10 ** 9)

for i in range(n):
    a, b = map(int, input().split())
    x = a + b
    y = a - b
    min_x = min(min_x, x)
    max_x = max(max_x, x)
    min_y = min(min_y, y)
    max_y = max(max_y, y)

print(max(max_x - min_x, max_y - min_y))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    d1 = []
    d2 = []
    for _ in range(N):
        x, y = map(int, input().split())
        d1.append(x+y)
        d2.append(x-y)
    d1_dist = max(d1) - min(d1)
    d2_dist = max(d2) - min(d2)
    print(max([d1_dist, d2_dist]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = []
ll = []
for _ in range(n):
    x, y = map(int, input().split())
    l.append((x+y, x, y))
    ll.append((x-y, x, y))
l.sort()
ll.sort()
ans1 = 0
ans2 = 0
#print(l)
#print(ll)

cnt = 0
while True:
    a = l[n-1-cnt]
    b = l[cnt]
    #print(a, b)
    if a[1] >= b[1] and a[2] >= b[2]:
        ans1 = abs(b[0]-a[0])
        #print(ans1, a, b)
        break
    if cnt >= n-1:
        break
    cnt += 1

cnt = 0
while True:
    a = ll[n-1-cnt]
    b = ll[cnt]
    if a[1] >= b[1] and b[2] >= a[2]:
        ans2 = abs(b[0]-a[0])
        #print(ans2, a, b)
        break
    if cnt >= n-1:
        break
    cnt += 1

print(max(ans1, ans2))

Submission status: Accepted

Solution code:
def main():
  f_0 = []
  f_1 = []
  n = int(input())
  for i in range(n):
    x, y = map(int, input().split())
    f_0.append(x-y)
    f_1.append(x+y)
  print(max(max(f_0)-min(f_0),max(f_1)-min(f_1)))
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
n = int(input())
lst_plus = []
lst_minus = []

for i in range(n):
  x,y = map(int,input().split())
  lst_plus.append(x+y)
  lst_minus.append(y-x)
  
lst_plus.sort()
lst_minus.sort()

A = lst_plus[-1] - lst_plus[0]
B = lst_minus[-1] - lst_minus[0]

print(max([A,B]))

Submission status: Accepted

Solution code:
N=int(input())

xy = []
d0, d1 = [],[]
for _ in range(N):
  x,y=map(int,input().split())
  d0.append(x-y)
  d1.append(x+y)
print(max(max(d0)-min(d0), max(d1)-min(d1)))

Submission status: Accepted

Solution code:
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
det = lambda p, q: p[0] * q[1] - p[1] * q[0]
sub = lambda p, q: (p[0] - q[0], p[1] - q[1])


def get_convex_hull(points):
    n = len(points)
    points.sort()
    size_convex_hull = 0
    ch = []
    for i in range(n):
        while size_convex_hull > 1:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    t = size_convex_hull
    for i in range(n - 2, -1, -1):
        while size_convex_hull > t:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    return ch[:-1]


mdist = -1
X = get_convex_hull(X)
used = [0] * len(X)
for index, start in enumerate(X):
    # if used[index] == 1:
    #     continue
    sx, sy = start
    maxv = -1
    maxi = -1
    for i, xi in enumerate(X):
        if i == index:
            continue
        x, y = xi
        # x, y = x - sx, y - sy
        # xx, yy = x + y, x - y
        # dist = max(abs(xx), abs(yy))
        dist = abs(x - sx) + abs(y - sy)
        # print("dist", dist)
        if maxv < dist:
            maxi = i
            maxv = dist
    # print("index, maxi", index, maxi)
    # used[maxi] = 1
    mdist = max(mdist, maxv)

print(mdist)

Submission status: Accepted

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

n = int(input())
a = [list(map(int,input().split())) for i in range(n)]

ax = sorted(a, key=lambda x:(x[0], x[1]))
ay = sorted(a, key=lambda x:(x[1], x[0]))

ans = 0
lx, ly = ax[0][0], ax[0][1]
ux, uy = ax[0][0], ax[0][1]
for i in range(n):
    if ax[i][0] - lx + ax[i][1] - ly < 0:
        lx, ly = ax[i][0], ax[i][1]
    if ax[i][0] - ux + ax[i][1] - uy > 0:
        ux, uy = ax[i][0], ax[i][1]
    ans = max(ans, ux-lx + uy - ly)
    
lx, ly = ax[0][0], ax[0][1]
ux, uy = ax[0][0], ax[0][1]
for i in range(n):
    if ax[i][0] - lx + ly - ax[i][1] < 0:
        lx, ly = ax[i][0], ax[i][1]
    if ax[i][0] - ux + uy - ax[i][1] > 0:
        ux, uy = ax[i][0], ax[i][1]
    ans = max(ans, ux-lx + ly - uy)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A=[]; B= []
for i in range(N):
  a,b = map(int,input().split())
  A.append((a+b))
  B.append((a-b))
A.sort()
B.sort()
ans = max(A[-1]-A[0],B[-1]-B[0])
print(ans)

Submission status: Accepted

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

xys = sorted(xys, key= lambda x: x[0])

answer = 0
a = []
b = []
for xy in xys:
    a.append(xy[0] + xy[1])
    b.append(xy[0] - xy[1])
    
print(max(max(a)-min(a), max(b)-min(b)))

Submission status: Accepted

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

data_sum=[]
for i in range(n):
    data_sum.append(data[i][0]+data[i][1])


data_sum_1=[]
for i in range(n):
    data_sum_1.append(data[i][1]-data[i][0])

d_1=max(data_sum)-min(data_sum)
d_2=max(data_sum_1)-min(data_sum_1)

print(max(d_1,d_2))

Submission status: Accepted

Solution code:
import numpy as np

f = open(0)
N = int(f.readline())
xy = np.fromstring(f.read(), dtype=np.int64, sep=' ').reshape((-1, 2)).T.copy()
x = xy[0]
y = xy[1]
c1 = x + y
c2 = x - y
ans = max(c1.max() - c1.min(), c2.max() - c2.min())
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    Z = []
    for i in range(N):
        x, y = MI()
        Z.append((x-y, x+y))
    # print(Z)
    minx = miny = INF
    maxx = maxy = -INF
    for z in Z:
        minx = min(minx, z[0])
        maxx = max(maxx, z[0])
        miny = min(miny, z[1])
        maxy = max(maxy, z[1])
    print(max(maxx-minx, maxy-miny))
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#coding:utf-8

N = int(input())

sa_lis = []
wa_lis = []

for i in range(N):
    x,y = map(int,input().split())
    sa_lis.append(x-y)
    wa_lis.append(x+y)

sa = max(sa_lis) - min(sa_lis)
wa = max(wa_lis) - min(wa_lis)

ans = max(sa,wa)

print("{}".format(ans))

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    def manhattan_distance(p1,p2):
        x1,y1 = p1
        x2,y2 = p2
        return abs(x1-x2) + abs(y1-y2)
    
    def chebyshev_distance(p1,p2):
        x1,y1 = p1
        x2,y2 = p2
        return max(abs(x1-x2),abs(y1-y2))



    N = II()
    # N = 10
    points = []
    from random import random
    f_0 = []
    f_1 = []
    for i in range(N):
        x,y = LMIIS()
        
        # x = int(random()*10**2)
        # y = int(random()*10**2)
        points.append((x,y))
        f_0.append(x-y)
        f_1.append(x+y)
    ans = 0
    ans = max(ans,max(f_0)-min(f_0))
    ans = max(ans,max(f_1)-min(f_1))
    
    print(ans)

    # ans2 = 0
    # for i in range(N):
    #     for j in range(i+1,N):
    #         tmp = manhattan_distance(points[i],points[j])
    #         if ans2 < tmp:
    #             max_pair2 = points[i],points[j]
    #             ans2 = tmp

    # print(ans2)
    # assert(ans==ans2)




main()

Submission status: Accepted

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


def f(x, y):
    return [x - y, x + y]


XY = []
for x, y in xy:
    XY.append(f(x, y))

large, small = [-float('inf'), -float('inf')], [float('inf'), float('inf')]
for i in range(2):
    for j in XY:
        large[i] = max(j[i], large[i])
        small[i] = min(j[i], small[i])

ans = max(large[0] - small[0], large[1] - small[1])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d1 = []
d2 = []
for i in range(n):
  x,y = map(int,input().split())
  d1.append(x-y)
  d2.append(x+y)
one = max(d1)-min(d1)
two = max(d2)-min(d2)
print(max(one,two))

Submission status: Accepted

Solution code:
N = int(input())

max_f_0 = -10**10
min_f_0 = 10**10
max_f_1 = -10**10
min_f_1 = 10**10

for _ in range(N):
    x, y = map(int, input().split(" "))
    f_0 = x - y
    f_1 = x + y
    
    if max_f_0 < f_0:
        max_f_0 = f_0
    if min_f_0 > f_0:
        min_f_0 = f_0
    if max_f_1 < f_1:
        max_f_1 = f_1
    if min_f_1 > f_1:
        min_f_1 = f_1
        
print(max((max_f_0-min_f_0), (max_f_1-min_f_1)))

Submission status: Accepted

Solution code:
N = int(input())
ls = []
lt= []
for _ in range(N):
    x,y = map(int, input().split())
    s = x+y
    t = x-y

    ls.append(s)
    lt.append(t)

print(max(max(ls) - min(ls),max(lt) - min(lt)))

Submission status: Accepted

Solution code:
n = int(input())
x,y = map(int,input().split())
lx = x+y
ly = (x-y)
maxlx = lx
minlx = lx
maxly = ly
minly = ly
for _ in range(n-1):
  x,y = map(int,input().split())
  lx = x+y
  ly = (x-y)
  maxlx = max(maxlx,lx)
  minlx = min(minlx,lx)
  maxly = max(maxly,ly)
  minly = min(minly,ly)
print(max(maxlx-minlx,maxly-minly))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XY = [list(map(int, input().split())) for _ in range(n)]

    X, Y = [], []
    for x, y in XY:
        X.append(x + y)
        Y.append(x - y)
    res = max(max(X) - min(X), max(Y) - min(Y))
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
N=int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

xyp=[]
xym=[]
for i in range(N):
    xyp.append(x[i]+y[i])
    xym.append(x[i]-y[i])
    
print(max(max(xyp)-min(xyp),-min(xym)+max(xym),max(xym)-min(xym),-min(xym)+max(xym)))

Submission status: Accepted

Solution code:
def calc(x, y):
    ans = 0
    ans += abs(x[0] - y[0])
    ans += abs(x[1] - y[1])
    return ans
N = int(input())
pts = [[0, 0] for i in range(N)]
d = (10 ** 9) // 2
dist_0 = 0
for i in range(N):
    x, y = list(map(int, input().split()))
    pts[i][0], pts[i][1] = x - d, y -d
    dist_0 = max(dist_0, calc(pts[i], [0, 0]))
s = set()
for pt in pts:
    if calc(pt,[0,0]) == dist_0:
        s.add(tuple(pt))
ans = 0
for pt in pts:
    for can in s:
        ans = max(ans, calc(pt, list(can)))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = [0] * n
Y = [0] * n
cx = []
cy = []

for i in range(n):
    X[i], Y[i] = map(int, input().split())
    cx.append(X[i] - Y[i])
    cy.append(X[i] + Y[i])

#print(X, Y)
#print(cx, cy)

ans = max(max(cx) - min(cx), max(cy) - min(cy))
print(ans)

Submission status: Accepted

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

a = []
b = []

for i in range(n):
  a.append(p[i][0] - p[i][1])
  b.append(p[i][0] + p[i][1])
  
ans = max(max(a)-min(a),max(b)-min(b))
print(ans)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, xyi):
    plus_max = - 10 ** 18
    plus_min = + 10 ** 18
    minus_max = - 10 ** 18
    minus_min = + 10 ** 18

    for x, y in xyi:
        plus_max = max(plus_max, x + y)
        plus_min = min(plus_min, x + y)
        minus_max = max(minus_max, x - y)
        minus_min = min(minus_min, x - y)
    ans = max(abs(plus_max - plus_min), abs(minus_max - minus_min))
    print(ans)


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    # Ai = [int(i) for i in input().split()]
    # Bi = [int(i) for i in input().split()]
    xyi = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, xyi)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Accepted

Solution code:
import heapq
N = int(input())
xy_s = [list(map(int,input().split())) for _ in range(N)]
XPYMAX = []
XPYMIN = []
XMYMAX = []
XMYMIN = []
heapq.heapify(XPYMAX)
heapq.heapify(XPYMIN)
heapq.heapify(XMYMAX)
heapq.heapify(XMYMIN)
answer = 0
for i, xy in enumerate(xy_s):
    x = xy[0]
    y = xy[1]
    heapq.heappush(XPYMAX,-(x+y))
    heapq.heappush(XMYMAX,-(x-y))
    heapq.heappush(XPYMIN,(x+y))
    heapq.heappush(XMYMIN,(x-y))

    if i == 0:
        continue

    xpy = x+y
    xmy = x-y
    xpymax = -XPYMAX[0]
    xpymin = XPYMIN[0]
    xmymax = -XMYMAX[0]
    xmymin = XMYMIN[0]
    dist = max(abs(xpymax-xpy), abs(xpymin-xpy), abs(xmymax-xmy), abs(xmymin-xmy))
    answer = max(dist, answer)
print(answer)

Submission status: Accepted

Solution code:
N = int(input())

xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

x_c = [x + y for (x, y) in zip(x, y)]
y_c = [x - y for (x, y) in zip(x, y)]

ans = max(x_c) - min(x_c)

ans_1 = max(y_c) - min(y_c)

if ans < ans_1:
    ans = ans_1

print(ans)

Submission status: Accepted

Solution code:
def main():
    inf=float("inf")
    n=int(input())
    mx=[-inf,-inf,-inf,-inf]
    mn=[inf,inf,inf,inf]
    for i in range(n):
        x,y=map(int,input().split())
        if x+y>mx[0] : mx[0]=x+y
        if x+y<mn[0] : mn[0]=x+y
        if x-y>mx[1] : mx[1]=x-y
        if x-y<mn[1] : mn[1]=x-y
        if -x-y>mx[2] : mx[2]=-x-y
        if -x-y<mn[2] : mn[2]=-x-y
        if -x+y>mx[3] : mx[3]=-x+y
        if -x+y<mn[3] : mn[3]=-x+y
    print(max([mx[i]-mn[i] for i in range(4)]))

main()

Submission status: Accepted

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a+b)
    B.append(a-b)
x=max(A)-min(A)
y=max(B)-min(B)
ans=max(x,y)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

P = [[int(_) for _ in input().split()] for n in range(N)]

X = []
Y = []
for x, y in P:
    X.append(x)
    Y.append(y)
mx = (min(X) + max(X)) // 2
my = (min(Y) + max(Y)) // 2

Qx = []
Qy = []
for x, y in P:
    x, y = x-mx, y-my
    Qx.append(x+y)
    Qy.append(x-y)

ax = max(Qx) - min(Qx)
ay = max(Qy) - min(Qy)
ans = max(ax, ay)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans = 0
ur = sorted(xy, key=lambda x: x[0]+x[1])[-1]
ul = sorted(xy, key=lambda x: x[1]-x[0])[-1]
dr = sorted(xy, key=lambda x: x[0]-x[1])[-1]
dl = sorted(xy, key=lambda x: -x[0]-x[1])[-1]

l = [ur, ul, dr, dl]
for i in l:
  for j in l:
    ans = max(ans, abs(i[0]-j[0])+abs(i[1]-j[1]))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
a = []
b = []
for i in range(n):
    a.append(x[i]-y[i])
    b.append(x[i]+y[i])
c = max(a) - min(a)
d = max(b) - min(b)
print(max(c,d))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    arr1 = []
    arr2 = []
    for x, y in XY:
        arr1.append(x)
        arr2.append(y)


    minX, maxX = min(arr1), max(arr1)
    minY, maxY = min(arr2), max(arr2)

    ans = 0
    # For all four corners, calculate the max distance differences
    for point in [(minX, minY), (maxX, minY), (minX, maxY), (maxX, maxY)]:
        minD = float('inf')
        maxD = float('-inf')
        for i in range(0, len(arr1)):
            distance = abs(arr1[i] - point[0]) + abs(arr2[i] - point[1])
            minD = min(minD, distance)
            maxD = max(maxD, distance)
        ans = max(ans, maxD - minD)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    N=int(input())
    A=[list(map(int,input().split())) for _ in range(N)]
    B=[]
    C=[]
    for x in A:
        B.append(x[0]+x[1])
        C.append(x[0]-x[1])
    b=max(B)-min(B)
    c=max(C)-min(C)
    d=[b,c]
    print(max(d))
    
   


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

Xmax = -2*10**9
Ymax = -2*10**9
Xmin = 2*10**9
Ymin = 2*10**9


for i in range(N):
    x, y = map(int, input().split())
    if (x + y >= Xmax):
        Xmax = x + y
    if (x + y <= Xmin):
        Xmin = x + y
    if (x - y >= Ymax):
        Ymax = x - y
    if (x - y <= Ymin):
        Ymin = x - y

print(max(Xmax - Xmin, Ymax - Ymin))

Submission status: Accepted

Solution code:
def ge():
    return map(int,input().split())
def main():
    #a,b,c,d=ge()
    #N=int(input())
    #a=list(map(int,input().split()))
    #a=input()
    N=int(input())
    f0=[]
    f1=[]
    for _ in range(N):
        X,Y=ge()
        f0.append(X-Y)
        f1.append(X+Y)
    ans=max(max(f0)-min(f0),max(f1)-min(f1))
    print(ans)
main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = []
    a = -float('inf') # x + y の最大
    b = float('inf') # x + y の最小
    c = -float('inf') # x - y の最大
    d = float('inf') # x - y の最小
    e = -float('inf') # -x+yの最大
    f = float('inf') # -x + yの最小
    g = -float('inf') # -x - yの最大
    h = float('inf') # -x - yの最小

    for _ in range(N):
        x, y = map(int, input().split())
        a = max(a, x + y)
        b = min(b, x + y)
        c = max(c, x - y)
        d = min(d, x - y)
        e = max(e, -x + y)
        f = min(f, -x + y)
        g = max(g, -x - y)
        h = min(h, -x - y)
    ans = a - b
    ans = max(ans, c-d)
    ans = max(ans, e-f)
    ans = max(ans, g-h)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
dmax_0=-10**10
dmin_0=10**10
dmax_1=-10**10
dmin_1=10**10
for i,j in xy:
  dmax_0=max(i-j,dmax_0)
  dmin_0=min(i-j,dmin_0)
  dmax_1=max(i+j,dmax_1)
  dmin_1=min(i+j,dmin_1)
print(max(dmax_0-dmin_0,dmax_1-dmin_1))

Submission status: Accepted

Solution code:
n = int(input())
x_list = []
y_list = []
for _ in range(n):
    x, y = map(int, input().split())
    x_list.append(x - y)
    y_list.append(x + y)
x_list.sort()
y_list.sort()
ans = max(x_list[-1] - x_list[0], y_list[-1] - y_list[0])
print(ans)

Submission status: Accepted

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

for x,y in XY:
  X_.append(x-y)
  Y_.append(x+y)

print(max(max(X_)-min(X_), max(Y_)-min(Y_)))

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    _xmin, _xmax = float("inf"), -float("inf")
    _ymin, _ymax = float("inf"), -float("inf")
    for i in range(N):
        x, y = list(map(int, input().split()))
        _x, _y = x - y, x + y
        _xmin = min(_x, _xmin)
        _xmax = max(_x, _xmax)
        _ymin = min(_y, _ymin)
        _ymax = max(_y, _ymax)
    print(max(_xmax-_xmin, _ymax-_ymin))


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
N = int(input())

XY_max = -10**10
XY_min = 10**10
YX_max = -10**10
YX_min = 10**10

for _ in range(N):
  x,y = map(int, input().split())
  XY_max = max(XY_max,x+y)
  XY_min = min(XY_min,x+y)
  YX_max = max(YX_max,x-y)
  YX_min = min(YX_min,x-y)

print(max(XY_max-XY_min,YX_max-YX_min))

Submission status: Accepted

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

#print(n, xy)
x_minus_y = []
x_plus_y = []
for i in range(n):
    x_minus_y.append(xy[i][0] - xy[i][1])
    x_plus_y.append(xy[i][0] + xy[i][1])
x_max = max(x_minus_y)
x_min = min(x_minus_y)
y_max = max(x_plus_y)
y_min = min(x_plus_y)

if x_max - x_min >= y_max - y_min:
    print(x_max - x_min)
else:
    print(y_max - y_min)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	E
# CreatedDate:  2020-09-13 21:46:52 +0900
# LastModified: 2020-09-13 22:18:13 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def f(x, y, version):
    if version == 0:
        return x+y
    else:
        return x-y

def main():
    N = int(input())
    ch_0 = []
    ch_1 = []
    trans_max = -1
    for _ in range(N):
        x, y = map(int, input().split())
        ch_0.append(f(x, y, 0))
        ch_1.append(f(x, y, 1))
    ans_0 = max(ch_0)-min(ch_0)
    ans_1 = max(ch_1)-min(ch_1)
    if ans_0 < ans_1:
        print(ans_1)
    else:
        print(ans_0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

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

x = np.array(x)
y = np.array(y)

xy0 = x + y
xy1 = x - y

print(max(max(xy0)-min(xy0),max(xy1)-min(xy1)))

Submission status: Accepted

Solution code:
n=int(input())
X=[]
Y=[]
#P=np.ndarray((0,2))
for i in range(n):
    x,y = map(int,input().split())
    X.append(x+y)
    Y.append(x-y)

    
ans = max(max(X)-min(X),max(Y)-min(Y))

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = []
B = []
for _ in range(N):
    x, y = map(int, readline().split())
    A.append(x+y)
    B.append(x-y)

a = max(A)
b = min(A)
c = max(B)
d = min(B)

print(max(abs(a-b),abs(c-d)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 20:41:42 2020

@author: liang
"""
#E
N = int(input())
d = list()
for i in range(N):
    x, y = map(int,input().split())
    d.append((x,y))

d.sort(key=lambda x:x[0]+x[1])
#print(d)

ans1 = abs(d[0][0] - d[N-1][0]) + abs(d[0][1] - d[N-1][1])

d.sort(key=lambda x:x[0]-x[1])

ans2 = abs(d[0][0] - d[N-1][0]) + abs(d[0][1] - d[N-1][1])

ans = max(ans1, ans2)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
pnts = [tuple(map(int, input().split())) for i in range(n)]

mxsum = max(map(lambda p: p[0]+p[1], pnts))
mnsum = min(map(lambda p: p[0]+p[1], pnts))
mxdif = max(map(lambda p: p[0]-p[1], pnts))
mndif = min(map(lambda p: p[0]-p[1], pnts))

print(max([mxsum - mnsum, mxdif-mndif]))