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())
XY = [list(map(int,input().split())) for _ in range(N)]

ans = 0

def measure(originX,originY):
    dist = []
    for X,Y in XY:
        dist.append(abs(X-originX)+abs(Y-originY))
    return max(dist)-min(dist)

originX = 0
originY = 0
ans = max(ans,measure(originX,originY))

originX = 10**9
originY = 0
ans = max(ans,measure(originX,originY))

originX = 0
originY = 10**9
ans = max(ans,measure(originX,originY))

originX = 10**9
originY = 10**9
ans = max(ans,measure(originX,originY))

print(ans)

Submission status: Accepted

Solution code:
def solve(xy):
    xy_diff = [] # x-yを追加(右上と左下でソートしたい)
    xy_dist = [] # x+yを追加(原典からの距離でソートしたい)
    for x,y in xy:
        xy_diff.append([x,y,x-y])
        xy_dist.append([x,y,x+y])
    xy_diff.sort(key = lambda x:x[2])
    xy_dist.sort(key = lambda x:x[2])

    return max(xy_diff[-1][2] - xy_diff[0][2], xy_dist[-1][2] - xy_dist[0][2])

def main():
    N = int(input())
    xy = [list(map(int,input().split())) for _ in range(N)]
    print(solve(xy))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
xbox=[]
ybox=[]
for i in range(n):
    x,y = map(int,input().split())
    xbox.append(x)
    ybox.append(y)
xmax=max(xbox)
xmin = min(xbox)
ymax=max(ybox)
ymin=min(ybox)
box1=[]
box2=[]
box3=[]
box4=[]
for i in range(n):
    box1.append(xmax+ymax-xbox[i]-ybox[i])
    box2.append(-xmin + ymax + xbox[i] - ybox[i])
    box3.append(xmax - ymax - xbox[i] + ybox[i])
    box4.append(-xmax - ymax + xbox[i] + ybox[i])
print(max([max(box1)-min(box1),max(box2)-min(box2),max(box3)-min(box3),max(box4)-min(box4)]))

Submission status: Accepted

Solution code:
beforex_plus_y=[]
beforex_minus_y=[]
for i in range(int(input())):
  xy=list(map(int,input().split()))
  beforex_plus_y.append(xy[0]+xy[1])
  beforex_minus_y.append(xy[0]-xy[1])

print(max(max(beforex_plus_y)-min(beforex_plus_y),max(beforex_minus_y)-min(beforex_minus_y)))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N = int(readline())
A = []
B = []
for _ in range(N):
    x, y = map(int, readline().split())
    A.append(x-y)
    B.append(x+y)
print(max(max(A) - min(A), max(B) - min(B)))

Submission status: Accepted

Solution code:
N = int(input())
z =[]
w = []
for i in range(N):
  x,y = map(int, input().split())
  z.append(x+y)
  w.append(x-y)
print(max(max(z)-min(z),max(w)-min(w)))

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    xy = list(nl() for _ in range(n))

    xpy = [x + y for x, y in xy]
    xmy = [x - y for x, y in xy]

    print(max(max(xpy) - min(xpy), max(xmy) - min(xmy)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
z = [x + y for x, y in xy]
w = [x - y for x, y in xy]
z.sort()
w.sort()

ans = max(z[-1] - z[0], w[-1] - w[0])
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
import bisect


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N =int(input())

    W_max =0
    W_min= 10**9+7
    Y_max= -10**9-1
    Y_min=10**9+7

    for i in range(N):
        x,y =map(int,input().split())
        W_max =max(W_max,x+y)
        W_min =min(W_min,x+y)
        Y_max =max(Y_max,x-y)
        Y_min =min(Y_min,x-y)

    print(max(W_max - W_min,Y_max - Y_min))






if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n=II()
	XY=[LI() for _ in range(n)]
	
	A=[]
	B=[]
	for x,y in XY:
		A.append(x+y)
		B.append(x-y)
	
	A.sort()
	B.sort()
	a=A[-1]-A[0]
	b=B[-1]-B[0]
	
	print(max(a,b))










if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
a1=float('inf')
a2=-float('inf')
a3=float('inf')
a4=-float('inf')

for i in range(n):
    cnt=a[i][0]+a[i][1]
    cnt1=a[i][0]-a[i][1]
    a1=min(a1,cnt)
    a2=max(a2,cnt)
    a3=min(cnt1,a3)
    a4=max(cnt1,a4)


print(max(a2-a1,a4-a3))

Submission status: Accepted

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

iti = -float("inf")
ni = -float("inf")
san = -float("inf")
yon = -float("inf")
for x,y in xy:
    iti = max(iti,x+y)
    ni = max(ni,x-y)
    san = max(san,-x+y)
    yon = max(yon,-x-y)

print(max(iti+yon,ni+san))

Submission status: Accepted

Solution code:
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
  X[i]=[X[i][0]+X[i][1],X[i][0]-X[i][1]]
print(max([max([X[i][j] for i in range(N)])-min([X[i][j] for i in range(N)]) for j in range(2)]))

Submission status: Accepted

Solution code:
N = int(input())
z = [0] * N
w = [0] * N
for i in range(N):
  x, y = map(int, input().split())
  z[i] = x + y
  w[i] = x - y
  
z = sorted(z)
w = sorted(w)
#print(z)
#print(w)
ans = max(abs(z[-1] - z[0]), abs(w[-1] - w[0]))
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
# L = [LIST() for i in range(N)]

zmax, zmin, wmax, wmin = -10 ** 9, 10 ** 9, -10 ** 9, 10 ** 9
# for i in range(N):
for i in range(N):
    x, y = MAP()
    zmax = max(zmax, x + y)
    zmin = min(zmin, x + y)
    wmax = max(wmax, x - y)
    wmin = min(wmin, x - y)
print(max(zmax - zmin, wmax - wmin))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
XY = [list(mapint()) for _ in range(N)]
XY.sort(key=lambda x:x[0]+x[1])
ans_1 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
XY.sort(key=lambda x:x[0]-x[1])
ans_2 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
print(max(ans_1, ans_2))

Submission status: Accepted

Solution code:
if __name__ == '__main__':

    N = int(input())
    x = []
    y = []

    for _ in range(N):
        x_, y_ = map(int, input().split())
        x.append(x_)
        y.append(y_)
    xpy = [a + b for a, b in zip(x, y)]
    xmy = [a - b for a, b in zip(x, y)]
    max_1 = max(xpy)
    min_1 = min(xpy)
    max_2 = max(xmy)
    min_2 = min(xmy)
    print(max(max_1 - min_1,max_2 - min_2))

Submission status: Accepted

Solution code:
n = int(input())

p, q = [], []
for _ in range(n):
    x, y = map(int, input().split())
    p.append(x + y)
    q.append(x - y)

p.sort()
q.sort()
print(max(max(p) - min(p), max(q) - min(q)))

Submission status: Accepted

Solution code:
N=int(input())
xp=yp=0
xn=yn=10**9
zs=[0]*N
ws=[0]*N
for i in range(N):
    xi,yi=map(int,input().split())
    zs[i]=xi+yi
    ws[i]=xi-yi
zs.sort()
ws.sort()
ans=max(zs[-1]-zs[0],ws[-1]-ws[0])
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
xy = [0] * n

xy_plus_max = -10 ** 10
xy_plus_min = 10 ** 10
xy_minus_max = -10 ** 10
xy_minus_min = 10 ** 10
for i in range(n):
    x, y = map(int, input().split())
    xy_plus_max = max(xy_plus_max, x + y)
    xy_plus_min = min(xy_plus_min, x + y)
    xy_minus_max = max(xy_minus_max, x - y)
    xy_minus_min = min(xy_minus_min, x - y)

print(max(xy_plus_max - xy_plus_min, xy_minus_max - xy_minus_min))

Submission status: Accepted

Solution code:
n = int(input())
xpy = []
xmy = []
for i in range(n):
    x,y = map(int,input().split())
    xpy.append(x+y)
    xmy.append(x-y)
xpy.sort()
xmy.sort()
print(max(abs(xpy[0]-xpy[-1]),abs(xmy[0]-xmy[-1])))

Submission status: Accepted

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

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

z = []
w = []

for x, y in xy:
    z.append(x + y)
    w.append(x - y)

ans = max(max(z) - min(z), max(w) - min(w))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xy = []
for _ in range(n):
    xy.append(list(map(int,input().split())))
a,b=xy[0]
m1=a+b
p1=xy[0]
m2=a-b
p2=xy[0]
p3=xy[0]
p4=xy[0]
m3=-a-b
m4=-a+b

for x,y in xy:
    if x+y > m1:
        m1=x+y
        p1 = [x,y]
    if x-y > m2:
        m2=x-y
        p2 = [x,y]
    if -x-y > m3:
        m3 = -x-y
        p3 = [x,y]
    if -x+y > m4:
        m4 = -x+y
        p4 = [x,y]
m = 0
for x0,y0 in [p1,p2,p3,p4]:
    for x1,y1 in [p1,p2,p3,p4]:
        dis=abs(x0-x1) + abs(y0-y1)
        if dis > m:
            m = dis
print(m)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


N=int(input())

x,y=map(int,input().split())
R=x
L=x
U=y
B=y

P=[(x,y)]
for i in range(1,N):
    x,y=map(int,input().split())
    P.append((x,y))
    if R<x:R=x
    if L>x:L=x
    if U<y:U=y
    if B>y:B=y

p=P[0]

UR=p
dUR=abs(R-p[0])+abs(U-p[1])
UL=p
dUL=abs(L-p[0])+abs(U-p[1])
BR=p
dBR=abs(R-p[0])+abs(B-p[1])
BL=p
dBL=abs(L-p[0])+abs(B-p[1])

for p in P[1:]:
    if dUR>abs(R-p[0])+abs(U-p[1]):
        UR=p
        dUR=abs(R-p[0])+abs(U-p[1])
    if dUL>abs(L-p[0])+abs(U-p[1]):
        UL=p
        dUL=abs(L-p[0])+abs(U-p[1])
    if dBR>abs(R-p[0])+abs(B-p[1]):
        BR=p
        dBR=abs(R-p[0])+abs(B-p[1])
    if dBL>abs(L-p[0])+abs(B-p[1]):
        BL=p
        dBL=abs(L-p[0])+abs(B-p[1])
    

ans=abs(UR[0]-BL[0])+abs(UR[1]-BL[1])

ans2=abs(UL[0]-BR[0])+abs(UL[1]-BR[1])
if ans2>ans: ans=ans2

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

n=inp()

min1=min2=int(1e15)
max1=max2=-int(1e15)

for i in range(n):
	x,y=invr()
	
	min1=min(min1,x+y)
	min2=min(min2,x-y)
	
	max1=max(max1,x+y)
	max2=max(max2,x-y)

ans=max(max1-min1,max2-min2)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
table = [[int(i) for i in input().split()] for N in range(N)]

a = -1
b = 10**10
c = -10**10
d = 10**10
for i in range(N):
    p = table[i][0]
    q = table[i][1]
    if a < p+q:
        a = p+q
    if b > p+q:
        b = p+q
    if c < p-q:
        c = p-q
    if d > p-q:
        d = p-q

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

Submission status: Accepted

Solution code:
N=int(input())

xp=yp=0
xn=yn=10**9
zs=[0]*N
ws=[0]*N
for i in range(N):
    xi,yi=map(int,input().split())
    zs[i]=xi+yi
    ws[i]=xi-yi
zs.sort()
ws.sort()
ans=max(zs[-1]-zs[0],ws[-1]-ws[0])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    a, b = map(int, input().split())
    x[i]=a+b
    y[i]=a-b
xmax=max(x)
xmin=min(x)
ymax=max(y)
ymin=min(y)
print(max(xmax-xmin,ymax-ymin))

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
    k,l=map(int,input().split())
    a.append((k-l,i))
    b.append((k+l,i))
    c.append((-k-l,i))
    d.append((-k+l,i))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d.sort(reverse=True)
print(max(a[0][0]+d[0][0],b[0][0]+c[0][0]))

Submission status: Accepted

Solution code:
import os
import heapq
import sys,threading
import math as mt
import operator
from copy import copy
from collections import defaultdict,deque
from io import BytesIO, IOBase

sys.setrecursionlimit(2*10 ** 5)
#threading.stack_size(2**27)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def pw(a,b,md):
    result=1
    while(b>0):
        if(b%2==1):
            result*=a
            result%=md
        a*=a
        a%=md
        b//=2
    return result%md


def inpt():
    return [int(k) for k in input().split()]


n=int(input())
ar=[]
br=[]
for _ in range(n):
    a,b=inpt()
    ar.append((a+b))
    br.append((a-b))

print(max(max(ar)-min(ar), max(br)-min(br)))


BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

Submission status: Accepted

Solution code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
xy = [list(x) for x in zip(*xy)]
a = [i+j for i,j in zip(xy[0],xy[1])]
b = [i-j for i,j in zip(xy[0],xy[1])]
aa = max(a) - min(a)
ba = max(b) - min(b)
print(max(aa,ba))

Submission status: Accepted

Solution code:
# Date [ 2020-09-13 23:02:13 ]
# Problem [ e.py ]
# Author Koki_tkg

import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    xy = [tuple(read_ints()) for _ in range(n)]
    diff = [x - y for x, y in xy]
    sum_ = [x + y for x, y in xy]
    print(max(max(sum_) - min(sum_), max(diff) - min(diff)))

if __name__ == '__main__':
    Main()

Submission status: Accepted

Solution code:
n=int(input())
z=[]
w=[]
for i in range(n):
  x,y=map(int,input().split())
  z.append(x+y)
  w.append(x-y)
ans=max(max(z)-min(z), max(w)-min(w))
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

N = int(input())
xs, ys = [], []
for _ in range(N):
    x, y = map(int, input().split())
    x2 = x+y
    y2 = x-y
    xs.append(x2)
    ys.append(y2)

#for i in range(N):
#    print(pts[i])

minX, maxX = min(xs), max(xs)
minY, maxY = min(ys), max(ys)
#print('# minX:', minX, '/ maxX:', maxX, file=sys.stderr)
#print('# minY:', minY, '/ maxY:', maxY, file=sys.stderr)

ans = 0
for x, y in zip(xs, ys):
    cs = [abs(x-minX), abs(x-maxX), abs(y-minY), abs(y-maxY)]
    m = max(cs)
    if m > ans:
        ans = m

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    n = int(input())
    xy = [list(map(int, input().split())) for i in range(n)]
    max_z, max_w, min_z, min_w = -10**20, -10**20, 10**20, 10**20
    ans = 0
    for p in xy:
        max_z, max_w = max(max_z, p[0] + p[1]), max(max_w, p[0] - p[1])
        min_z, min_w = min(min_z, p[0] + p[1]), min(min_w, p[0] - p[1])
    ans = max(max_z - min_z, max_w - min_w)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
l=[list(map(int,input().split())) for _ in range(int(input()))]
f=sorted([x+y for x,y in l])
g=sorted([x-y for x,y in l])
print(max(f[-1]-f[0],g[-1]-g[0]))

Submission status: Accepted

Solution code:
N = int(input())
z = [None] * N
w = [None] * N
for i in range(N):
    x, y = map(int, input().split())
    z[i] = x + y
    w[i] = x - y

print(max(max(z)-min(z), max(w)-min(w)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    U = []
    V = []
    for _ in range(N):
        x, y = map( int, input().split())
        u, v = x+y, x-y
        U.append(u)
        V.append(v)
    U.sort()
    V.sort()
    print( max(U[-1]-U[0], V[-1]-V[0]))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for _i in range(n)]
x = [i+j for i, j in xy]
y = [i-j for i, j in xy]
x.sort()
y.sort()
print(max(abs(x[0]-x[-1]), abs(y[0]-y[-1])))

Submission status: Accepted

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
f0 = sorted([x+y for x, y in xy])
f1 = sorted([x-y for x, y in xy])
print(max(f0[-1]-f0[0], f1[-1]-f1[0]))

Submission status: Accepted

Solution code:
a,*b=[],
for z in[*open(0)][1:]:x,y=map(int,z.split());a+=x+y,;b+=x-y,
print(max(abs(max(a)-min(a)),abs(max(b)-min(b))))

Submission status: Accepted

Solution code:
N=int(input())
Z=[0]*N
W=[0]*N

for i in range(N):
    x,y=map(int,input().split())
    Z[i]=x+y
    W[i]=x-y

alpha=max(Z)-min(Z)
beta=max(W)-min(W)
print(max(alpha,beta))

Submission status: Accepted

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

XplusY = [x + y for x, y in XY]
XminusY = [x - y for x, y in XY]

print(max([max(XplusY) - min(XplusY), max(XminusY) - min(XminusY)]))

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    x, y = i2(N)

    Mw = max(x[i]+y[i] for i in range(N))
    mw = min(x[i]+y[i] for i in range(N))
    Mz = max(x[i]-y[i] for i in range(N))
    mz = min(x[i]-y[i] for i in range(N))

    print(max(Mz-mz, Mw-mw))
    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input().strip())
l = []
 
for i in range(n):
    x, y = map(int, input().split())
    a = y + x
    b = y - x
    l.append([x, y, a, b])
 
la = sorted(l, key=lambda z: z[2])
lb = sorted(l, key=lambda z: z[3])
 
print(max(abs(la[0][0] - la[-1][0]) + abs(la[0][1]-la[-1][1]),
          abs(lb[0][0] - lb[-1][0]) + abs(lb[0][1]-lb[-1][1])
          )
      )

Submission status: Accepted

Solution code:




def chebyshev_0(a, b):
    return a - b
def chebyshev_1(a, b):
    return a + b

N = int(input())
X = [0] * N
Y = [0] * N

for i in range(N):
    X[i], Y[i] = map(int, input().split())

max_0 = - (10 ** 9) - 1
min_0 = 2 * (10 ** 9)
for x, y in zip(X, Y):
    if chebyshev_0(x, y) > max_0:
        max_0 = chebyshev_0(x, y)
    if chebyshev_0(x, y) < min_0:
        min_0 = chebyshev_0(x, y)
l0 = abs(max_0 - min_0)

max_1 = - (10 ** 9) - 1
min_1 = 2 * (10 ** 9)
for x, y in zip(X, Y):
    if chebyshev_1(x, y) > max_1:
        max_1 = chebyshev_1(x, y)
    if chebyshev_1(x, y) < min_1:
        min_1 = chebyshev_1(x, y)
l1 = abs(max_1 - min_1)

print(max([l0, l1]))

Submission status: Accepted

Solution code:
N = int(input())

a = [0 for i in range(N)]
b = [0 for i in range(N)]

for i in range(N):
  x, y = list(map(int, input().split()))
  a[i] = x + y
  b[i] = x - y

a = sorted(a)
b = sorted(b)
print(max(a[N-1]-a[0], b[N-1]-b[0]))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    mat = []
    a = []
    b = []

    for _ in range(N):
        x, y = map(int, readline().split())
        a.append(x + y)
        b.append(x - y)

    d1 = max(a) - min(a)
    d2 = max(b) - min(b)

    print(max(d1,d2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
Z=[0]*N
W=[0]*N

for i in range(N):
  x, y = map(int, input().split())
  Z[i]=x+y
  W[i]=x-y

print(max(max(Z)-min(Z),max(W)-min(W)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def MI():
    return map(int, input().split())

n = int(input())
z=[]
w=[]
for i in range(n):
    x,y=MI()
    z.append(x+y)
    w.append(x-y)

print(max(max(z)-min(z), max(w)-min(w)))

Submission status: Accepted

Solution code:
n = int(input())
xx = []
yy = []
for _ in range(n):
    x, y = map(int, input().split())
    xx.append(x + y)
    yy.append(x - y)

print(max(max(xx) - min(xx), max(yy) - min(yy)))

Submission status: Accepted

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


def get_output():
    dist = [0 for _ in range(N)]
    X, Y = [], []

    for i, (x, y) in enumerate(xy):
        x, y = x-y, x+y
        X.append(x)
        Y.append(y)

    a = max(X) - min(X)
    b = max(Y)-min(Y)
    return max(a, b)


print(get_output())

Submission status: Accepted

Solution code:
n = int(input())
c = [[int(i) for i in input().split()] for i in range(n)]
z = []
w = []
for i in range(n):
    z.append(c[i][0] + c[i][1])
    w.append(c[i][1] - c[i][0])
ans = max(max(z)-min(z), max(w)-min(w))
print(ans)

Submission status: Accepted

Solution code:

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

z = [x + y for x, y in X]
w = [x - y for x, y in X]

print(max(max(z) - min(z), max(w) - min(w)))

Submission status: Accepted

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

ws = [x+y for x,y in xys]
zs = [x-y for x,y in xys]

print(max([max(ws)-min(ws), max(zs)-min(zs)]))

Submission status: Accepted

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    a0 = a1 = a2 = a3 = INF

    ans = 0
    for _ in range(int(input())):
        x, y = map(int, input().split())
        ans = max(ans, x + y - a0, x - y - a1, -x + y - a2, -x - y - a3)
        a0 = min(a0, x + y)
        a1 = min(a1, x - y)
        a2 = min(a2, -x + y)
        a3 = min(a3, -x - y)

    print(ans)
resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
pos_x_list = []
pos_y_list = []

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

print(max(max(pos_x_list) - min(pos_x_list), max(pos_y_list) - min(pos_y_list)))

Submission status: Accepted

Solution code:
n = int(input())
xy = [[int(i) for i in input().split()] for j in range(n)]

mi = 10**10
ma = 0

for i in range(n):
    tmp = xy[i][0] + xy[i][1]
    if tmp > ma:
        ma = tmp
    #print(tmp,mi)
    if tmp < mi:
        mi = tmp
        
ans = ma-mi

mi = 10**10
ma = -10**10

for i in range(n):
    tmp = xy[i][0] - xy[i][1]
    if tmp > ma:
        ma = tmp
    #print(tmp,mi)
    if tmp < mi:
        mi = tmp
        
print(max(ans,ma-mi))

Submission status: Accepted

Solution code:
N=int(input())

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

Submission status: Accepted

Solution code:
n = int(input())
XY = [tuple(map(int, input().split())) for i in range(n)]
A = [x + y for x, y in XY]
B = [x - y for x, y in XY]
print(max(max(A) - min(A), max(B) - min(B)))

Submission status: Accepted

Solution code:
N=int(input())
answer=0

xylist=[]
pxylist=[]
mxylist=[]
for _ in range(N):
  x,y=map(int,input().split())
  xylist.append((x,y))
  pxylist.append(x+y)
  mxylist.append(x-y)
pxylist.sort()
mxylist.sort()

answer=max(pxylist[-1]-pxylist[0],mxylist[-1]-mxylist[0])
print(answer)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
A,B = [],[]  # x+y,x-y たちのリスト
for i in range(N):
    x,y = MI()
    A.append(x+y)
    B.append(x-y)

print(max(max(A)-min(A),max(B)-min(B)))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

N = int(input())
X = []
Y = []
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

ans1 = []
ans2 = []
for i in range(N):
    ans1.append(X[i] + Y[i])
    ans2.append(Y[i] - X[i])
ans1.sort()
ans2.sort()

a = ans1[-1] - ans1[0]
b = ans2[-1] - ans2[0]

print(max(a,b))

Submission status: Accepted

Solution code:
n=int(input())

x=[]
y=[]
for _ in range(n):
    xx,yy=map(int,input().split())
    x.append(xx)
    y.append(yy)

def maxAbsValExpr(arr1, arr2):
    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)
    return ans


print(maxAbsValExpr(x, y))

Submission status: Accepted

Solution code:
N = int(input())
X = [[] for _ in range(N)]
z = [0 for _ in range(N)]
w = [0 for _ in range(N)]
for i in range(N):
    X[i] = list(map(int, input().split()))
    z[i] = X[i][0] +X[i][1]
    w[i] = X[i][0] -X[i][1]

ans = max(max(z)-min(z), max(w)-min(w))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Zlist=[]
Wlist = []
for i in range(N):
    x,y = map(int,input().split())
    z = x+y
    w = x-y
    Zlist.append(z)
    Wlist.append(w)
Zlist.sort()
Wlist.sort()
print(max(Zlist[-1]-Zlist[0],Wlist[-1]-Wlist[0]))

Submission status: Accepted

Solution code:
X = []
Y = []
N = int(input())
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
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def floor(a, b): return -(-a // b)


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


N = z()
X, Y = [], []
dist = [0]*(N)  # 原点からの距離
for i in range(N):
    x, y = zz()
    x, y = x-y, x+y

    X.append(x)
    Y.append(y)

a = max(X) - min(X)
b = max(Y)-min(Y)
print(max(a, b))

Submission status: Accepted

Solution code:
N = int(input())

l = [None] * N

for i in range(N):
    l[i] = list(map(int, input().split()))

minX = min([e[0] for e in l])
minY = min([e[1] for e in l])
maxX = max([e[0] for e in l])
maxY = max([e[1] for e in l])

def d(_a, _b):
    return abs(_a[0]-_b[0])+abs(_a[1]-_b[1])

s0 = min([d([minX,minY], e) for e in l])
s1 = min([d([maxX,maxY], e) for e in l])
 
t0 = min([d([maxX,minY], e) for e in l])
t1 = min([d([minX,maxY], e) for e in l])
 

print(d([minX,minY], [maxX,maxY]) - min(s0+s1, t0+t1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

n=int(input())
xs=[]
ys=[]
for _ in range(n):
    x,y=map(int,input().split())
    tx,ty=x+y,x-y
    xs.append(tx)
    ys.append(ty)
xs=sorted(xs)
ys=sorted(ys)
ans=max(abs(xs[-1]-xs[0]),abs(ys[-1]-ys[0]))
print(ans)

Submission status: Accepted

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

def f(x,y):
  return x-y

def g(x,y):
  return x+y
  
print(max(max([f(x[i],y[i]) for i in range(n)])-min([f(x[i],y[i]) for i in range(n)]), max([g(x[i],y[i]) for i in range(n)])-min([g(x[i],y[i]) for i in range(n)])))