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: Wrong Answer

Solution code:
n = int(input())


# x_max = 0
# x_min = 10**10
# y_max = 0
# y_min = 10**10


# 最初の2点
# x0, y0 = map(lambda x: int(x), input().split())
# x1, y1 = map(lambda x: int(x), input().split())

edge0 = list(map(lambda x: int(x), input().split()))
edge1 = list(map(lambda x: int(x), input().split()))
dis = abs(edge0[0]-edge1[0]) + abs(edge0[1]-edge1[1])

# dis = abs(x0 - x1) + abs(y0 - y1)
# x_max = max(x0, x1)
# x_min = min(x0, x1)
# y_max = max(y0, y1)
# y_min = min(y0, y1)

for  _ in range(n-2):
    x, y = map(lambda x: int(x), input().split())
    if (x < min(edge0[0], edge1[0])) | (max(edge0[0], edge1[0]) < x) | (y < min(edge0[1], edge1[1])) | (max(edge0[1], edge1[1]) < y):
            dis_from_edge0 = abs(x-edge0[0]) + abs(y-edge0[1])
            dis_from_edge1 = abs(x-edge1[0]) + abs(y-edge1[1])

            # 更新なし
            if max(dis_from_edge0, dis_from_edge1) <= dis:
                continue
            # どちらも更新
            if max(dis_from_edge0, dis_from_edge1) > dis:
                if dis_from_edge0 < dis_from_edge1:
                    dis  = dis_from_edge1
                    edge0 = [x, y]
                else:
                    dis = dis_from_edge0
                    edge1 = [x, y]
                continue
            if dis_from_edge0 > dis:
                dis = dis_from_edge0
                edge1 = [x, y]
                continue
    #       if dis_from_edge1 > dis:
            dis = dis_from_edge1
            edge1 = [x, y]
print(dis)

Submission status: Wrong Answer

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


n = int(input())
arr = set()
for i in range(n):
	x ,y = map(int , input().split())
	arr.add((x,y))
arr = sorted(arr , key = lambda x : (x[0]+x[1]))
#print(arr)
#print(abs(arr[0][0] - arr[len(arr)-1][0]) + abs(arr[0][1] - arr[len(arr)-1][1]))
ans = float("-inf")
for i in range(1,len(arr)):
	#print("!!",abs(arr[0][0] - arr[i][0]) , abs(arr[0][1] - arr[i][1]))
	ans = max(ans , abs(arr[0][0] - arr[i][0]) + abs(arr[0][1] - arr[i][1]))
print(ans)






'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



threading.Thread(target=solve).start()
'''

Submission status: Wrong Answer

Solution code:
n = int(input())
min = 10000000000
max = -10000000000
l = []
r = []
ln = 0
rn = 0
for _ in range(n):
    x, y = map(int,input().split())
    if x+y <= min:
        if x+y == min:
            l.append([x,y])
            ln+=1
        else:
            l.append([x,y])
            ln = 1
        min = x+y
    elif x+y >= max:
        if x + y == max:
            r.append([x,y])
            rn+=1
        else:
            r.append([x,y])
            rn = 1
res = 0
for i in range(ln):
    for j in range(rn):
        dis = abs(l[i][0]-r[j][0]) + abs(r[j][1]-l[i][1])
        if dis>res:
            res = dis
print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[0,0] for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    L[i][0]=a
    L[i][1]=b
L1=sorted(L, key=lambda x:x[0])
L2=sorted(L, key=lambda x:x[1])
ans1=abs(L1[0][0]-L2[0][0])+abs(L1[0][1]-L2[0][1])
ans2=abs(L1[-1][0]-L2[0][0])+abs(L1[-1][1]-L2[0][1])
ans3=abs(L1[0][0]-L2[-1][0])+abs(L1[0][1]-L2[-1][1])
ans4=abs(L1[-1][0]-L2[-1][0])+abs(L1[-1][1]-L2[-1][1])
print(max(ans1,ans2,ans3,ans4))

Submission status: Wrong Answer

Solution code:
# author:  Taichicchi
# created: 13.09.2020 21:51:21

import sys


def dist(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])


N = int(input())

ls = []

for i in range(N):
    ls.append(list(map(int, input().split())))

ls.sort(key=lambda x: (x[0], x[1]))

ans = 0

for i in range(1, N):
    ans = max(ans, dist(ls[0], ls[i]))

ls.sort(key=lambda x: (x[1], x[0]))

for i in range(1, N):
    ans = max(ans, dist(ls[0], ls[i]))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(1000000)


def solve(N, XYs):
    def d(p1, p2):
        return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

    def xmax():
        return max(XYs, key=lambda x: x[0])

    def ymax():
        return max(XYs, key=lambda x: x[1])

    def xmin():
        return min(XYs, key=lambda x: x[0])

    def ymin():
        return min(XYs, key=lambda x: x[1])

    x_max = xmax()
    x_min = xmin()
    y_max = ymax()
    y_min = ymin()

    ans = max(
        d(x_max, x_min),
        d(x_max, y_min),
        d(x_max, y_max),
        d(x_min, y_max),
        d(x_min, y_min),
        d(y_max, y_min),
    )
    return ans


if __name__ == "__main__":
    N = int(input())
    XYs = [tuple(map(int, input().split(" "))) for _ in range(N)]

    print(solve(N, XYs))

Submission status: Wrong Answer

Solution code:
n = int (input())

xy = []

def dist(a, b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])
    
for i in range(n):
    x, y = map(int,input().split())
    xy.append([x, y])

xy.sort(key = lambda x: x[0]+x[1])

print(dist(xy[0], xy[-1]))

Submission status: Wrong Answer

Solution code:
import numpy as np
from scipy.special import comb

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

p = np.array(p)

ans = 0
for _ in range(n):
  ans = max(ans,max((np.sum(p-p[0],axis=1))))
  p = np.delete(p,0,0)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dic = defaultdict(list)
N = int(input())
l = []
z = []
for _ in range(N):
    x, y = map(int, input().split())
    l.append([x, y])
    z.append(x+y)
z.sort()
ans = z[-1]-z[0]
    
for t in l:
    a = t[0]+t[1]
    dic[a].append(t)
for u in dic:
    dic[u].sort()
    b = dic[u][-1][0]-dic[u][0][0]
    ans = max(2*b,ans)
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for x, y in Q:
    ans = max(ans, abs(x) + abs(y))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

x, y = map(int, input().split())

rt = (x, y)
rb = (x, y)
lt = (x, y)
lb = (x, y)

for _ in range(N-1):
    x, y = map(int, input().split())
    if (x + y - rt[0] - rt[1] > 0):
        rt = (x, y)
    if (x + y - lb[0] - lb[1] < 0):
        lb = (x, y)
    if (x - y - rb[0] - rb[1] > 0):
        rb = (x, y)
    if (x - y - lt[0] - lt[1] < 0):
        lt = (x, y)

def dist(p, q):
    return (abs(p[0]-q[0]) + abs(p[1]-q[1]))
print(max(dist(rt, lb), dist(rb, lt)))

Submission status: Wrong Answer

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

a = 2000000000
b = 0
for x, y in p:
    a = min(a, x + y)
    b = max(b, x + y)
print(b - a)

Submission status: Wrong Answer

Solution code:
n = int(input())
table = []
maxl,minl = [],[]
for _ in range(n):
  x,y = map(int,input().split())
  table.append([x,y])
xmax,xmin = max(table)[0],min(table)[0]
ymax,ymin = max(table,key=lambda x:x[1])[1],min(table,key=lambda x:x[1])[1]
for x,y in table:
  if x==xmax or y==ymax:
    maxl.append([x,y])
  if x==xmin or y==ymin:
    minl.append([x,y])
ans = 0
for x,y in maxl:
  for k,l in minl:
    ans = max(abs(x-k)+abs(y-k),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0 for _ in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
xx = sum([i[0] for i in x])/n
yy = sum([i[1] for i in x])/n
for i in x:
    i.append(abs(xx-i[0]) + abs(yy-i[1]))
x.sort(key = lambda s:s[2])
ans = 0
for i in x:
    ans = max(ans, abs(x[-1][0] - i[0]) + abs(x[-1][1] - i[1]))
    ans = max(ans, abs(x[-2][0] - i[0]) + abs(x[-2][1] - i[1]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
plus = []
for i in range(N):
    x,y = map(int,input().split())
    plus.append([x+y,x,y])
plus.sort()

ans = 0
fxy,fx,fy = plus[0]
for i in range(1,N):
    sxy,sx,sy = plus[i]
    if fxy == sxy:
        if fx != sx or fy != sy:
            ans = max(ans, abs(fx-sx)+abs(fy-sy))
    else:
        ans = max(ans, sxy-fxy)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

n = readInt()
minPoint,maxPoint = [],[]
allPOints = []
for _ in range(n):
    x,y = readIntList()
    allPOints.append([x,y])

allPOints.sort(key=lambda x: x[0])
a = allPOints[0]
b = allPOints[-1]
allPOints.sort(key=lambda x: x[1])
c = allPOints[0]
d = allPOints[-1]

def getDist(x,y):
    return abs(a[0]-y[0]) + abs(x[1]-y[1])

res = max(getDist(a,b),getDist(a,c),getDist(a,d),getDist(b,c),getDist(b,d),getDist(c,d))

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = set()
for _ in range(N):
    x, y = map(int, input().split())
    if (x, y) not in p:
        p.add((x, y))
p = [x + y for x, y in p]
p.sort()
print(abs(p[0] - p[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
max = 0
s = 0
for i in range(n):
	x[i],y[i] = map(int,input().split())
for j in range(n):
	if max < abs(x[0] - x[j]) + abs(y[0] - y[j]):
		max = abs(x[0] - x[j]) + abs(y[0] - y[j])
		s = j
for k in range(n):
	if max < abs(x[s] - x[j]) + abs(y[s] - y[j]):
		max = abs(x[s] - x[j]) + abs(y[s] - y[j])
print(max)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
max=0
for i in range(n):
  k,kk=map(int, input().split())
  m=list(l)
  print(l)
  while(len(m)>0):
    h=m.pop()
    ma=abs(h[0]-k)+abs(h[1]-kk)
    if ma>max:
      max=ma
  l.append([k,kk])
print(max)

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[]
  for _ in range(n):
    a,b=LI()
    l.append((a,b,a+b))

  l=sorted(l,key=lambda x:x[2])

  return abs(l[-1][0]-l[0][0])+abs(l[-1][1]-l[0][1])

# main()
print(main())

Submission status: Wrong Answer

Solution code:
input=__import__('sys').stdin.readline
def getdist(a,b):return abs(a[0]-b[0])+abs(a[1]-b[1])
n=int(input())
s=[]
for _ in range(n):
    s+=[*map(int,input().split())],
s.sort()
ans=0
for i in s:
    ans=max(ans,getdist(s[0],i))
    ans=max(ans,getdist(s[-1],i))
ans=max(ans,getdist(s[-1],s[-2]))
ans=max(ans,getdist(s[0],s[1]))
s.sort(key=lambda x:x[1])
for i in s:
    ans=max(ans,getdist(s[0],i))
    ans=max(ans,getdist(s[-1],i))
ans=max(ans,getdist(s[-1],s[-2]))
ans=max(ans,getdist(s[0],s[1]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

P=[tuple(map(int,input().split())) for _ in [0]*N]

xM,yM,xm,ym=0,0,10**9+7,10**9+7
xM_list,xm_list,yM_list,ym_list=[],[],[],[]

for i in range(N):
    if xM<P[i][0]:
        xM=P[i][0]
        xM_list=[P[i]]
    elif xM==P[i][0]:
        xM_list.append(P[i])
    if xm>P[i][0]:
        xm=P[i][0]
        xm_list=[P[i]]
    elif xm==P[i][0]:
        xm_list.append(P[i])
    if yM<P[i][1]:
        yM=P[i][1]
        yM_list=[P[i]]
    elif yM==P[i][1]:
        yM_list.append(P[i])
    if ym>P[i][1]:
        ym=P[i][1]
        ym_list=[P[i]]
    elif ym==P[i][1]:
        ym_list.append(P[i])

xm_list.sort(lambda x:x[1])
xM_list.sort(lambda x:x[1])
ym_list.sort(lambda x:x[0])
yM_list.sort(lambda x:x[0])

goodP=[]

if len(xm_list)>1:
    goodP.append(xm_list[-1])
    goodP.append(xm_list[0])
else:
    goodP.append(xm_list[0])
if len(xM_list)>1:
    goodP.append(xM_list[-1])
    goodP.append(xM_list[0])
else:
    goodP.append(xM_list[0])
if len(ym_list)>1:
    goodP.append(ym_list[-1])
    goodP.append(ym_list[0])
else:
    goodP.append(ym_list[0])
if len(yM_list)>1:
    goodP.append(yM_list[-1])
    goodP.append(yM_list[0])
else:
    goodP.append(yM_list[0])

res=[]
for i in range(len(goodP)):
    for j in range(len(goodP)):
        if not i<j:
            continue
        res.append(abs(goodP[i][0]-goodP[j][0])+abs(goodP[i][1]-goodP[j][1]))
print(max(res))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0 for _ in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
xx = sum([i[0] for i in x])/n
yy = sum([i[1] for i in x])/n
for i in x:
    i.append(abs(xx-i[0]) + abs(yy-i[1]))
x.sort(key = lambda s:s[2])
ans = 0
for i in x:
    ans = max(ans, abs(x[-1][0] - i[0]) + abs(x[-1][1] - i[1]))
print(ans)

Submission status: Wrong Answer

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

B = sorted([x+y for x,y in A])
print(B[-1] - B[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
plus = []
for i in range(N):
    x,y = map(int,input().split())
    plus.append([x+y,x,y])
plus.sort()

ans = 0
fxy,fx,fy = plus[0]
for i in range(1,N):
    sxy,sx,sy = plus[i]
    if fxy == sxy:
        if fx != sx or fy != sy:
            ans = max(ans, abs(fx-sx)-abs(fy-sy))
    else:
        ans = max(ans, sxy-fxy)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

n = readInt()
minPoint,maxPoint = [],[]
allPOints = []
for _ in range(n):
    x,y = readIntList()
    allPOints.append([x,y])

allPOints.sort(key=lambda x: x[0])
a = allPOints[0]
b = allPOints[-1]
allPOints.sort(key=lambda x: x[1])
c = allPOints[0]
d = allPOints[0]

def getDist(x,y):
    return abs(a[0]-y[0]) + abs(x[1]-y[1])

res = max(getDist(a,b),getDist(a,c),getDist(a,d),getDist(b,c),getDist(b,d),getDist(c,d))

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
if x1+y1 > x2+y2:
    pxmax, pymax = x1, y1
    pxmin, pymin = x2, y2
else:
    pxmax, pymax = x2, y2
    pxmin, pymin = x1, y1
    
if x1-y1 > x2-y2:
    mxmax, mymax = x1, y1
    mxmin, mymin = x2, y2
else:
    mxmax, mymax = x2, y2
    mxmin, mymin = x1, y1

for i in range(N-2):
    x, y = map(int, input().split())
    if x+y > pxmax+pymax:
        pxmax, pymax = x, y
    elif x+y < pxmin+pymin:
        pxmin, pymin = x, y
    
    if x1-y1 > mxmax-mymax:
        mxmax, mymax = x, y
    elif x1-y1 < mxmin-mymin:
        mxmin, mymin = x, y
        
print(max(abs(pxmax-pxmin)+abs(pymax-pymin), abs(mxmax-mxmin)+abs(mymax-mymin)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dic = defaultdict(list)
N = int(input())
l = []
z = []
for _ in range(N):
    x, y = map(int, input().split())
    l.append([x, y])
    z.append(x+y)
z.sort()
temp = z[-1]-z[0]
    
for t in l:
    a = t[0]+t[1]
    dic[a].append(t)
for u in dic:
   
    dic[u].sort()
    b = dic[u][-1][0]-dic[u][0][0]
    ans = max(2*b, temp)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

def manhattan(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1-y2)

N = I()
x1, y1 = I()
x2, y2 = I()

ans = manhattan(x1, y1, x2, y2)
for _ in range(2, N):
    x3, y3 = I()
    
    tl = manhattan(x1, y1, x3, y3)
    tr = manhattan(x2, y2, x3, y3)
    
    if tl > tr and tl > ans:
        x2, y2 = x3, y3
    elif tr > tl and tr > ans:
        x1, y1 = x3, y3

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    n,m = map(int,input().split())
    l.append(n+m)

print (max(l)-min(l))

Submission status: Wrong Answer

Solution code:
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
mod = 10**9 + 7

#maincode-------------------------------------------------

n = ini()
mx = 0
mn = 10**9+5
for i in range(n):
    x,y = inm()
    mx = max(mx,x+y)
    mn = min(mn,x+y)
print(mx-mn)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
res, n = 0, len(x)
for p, q in [[1, 1], [1, -1], [-1, 1], [-1, -1]]:
    smallest = p * x[0] + q * y[0] + 0
    for i in range(n):
        cur = p * x[i] + q * y[i] + i
        res = max(res, cur - smallest)
        smallest = min(smallest, cur)
print(res-1)

Submission status: Wrong Answer

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

res = 0
for i in range(n):
    for j in range(i, n-1):
        res = max(res, abs(x[i] - x[j]) + abs(y[i] - y[j]))

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
x, y = map(int, input().split())
A = B = C = D = E = F = G = H = [x, y]
for _ in range(N - 1):
    x, y = map(int, input().split())
    if x <= A[0] and y <= A[1]:
        A = [x, y]
    elif x <= B[0] and y >= B[1]:
        B = [x, y]
    elif x >= C[0] and y >= C[1]:
        C = [x, y]
    elif x >= D[0] and y <= D[1]:
        D = [x, y]
    elif (x <= A[0] or x <= B[0]) and A[1] <= y <= B[1]:
        E = [x, y]
    elif (y >= B[1] or y >= C[1]) and B[0] <= x <= C[0]:
        F = [x, y]
    elif (x >= C[0] or x >= D[0]) and D[1] <= y <= C[1]:
        G = [x, y]
    elif (y <= A[1] or y <= D[1]) and A[0] <= x <= D[0]:
        H = [x, y]
L = []
L.append(abs(A[0] - B[0]) + abs(A[1] - B[1]))
L.append(abs(A[0] - C[0]) + abs(A[1] - C[1]))
L.append(abs(A[0] - D[0]) + abs(A[1] - D[1]))
L.append(abs(A[0] - E[0]) + abs(A[1] - E[1]))
L.append(abs(A[0] - F[0]) + abs(A[1] - F[1]))
L.append(abs(A[0] - G[0]) + abs(A[1] - G[1]))
L.append(abs(A[0] - H[0]) + abs(A[1] - H[1]))
L.append(abs(B[0] - C[0]) + abs(B[1] - C[1]))
L.append(abs(B[0] - D[0]) + abs(B[1] - D[1]))
L.append(abs(B[0] - E[0]) + abs(B[1] - E[1]))
L.append(abs(B[0] - F[0]) + abs(B[1] - F[1]))
L.append(abs(B[0] - G[0]) + abs(B[1] - G[1]))
L.append(abs(B[0] - H[0]) + abs(B[1] - H[1]))
L.append(abs(C[0] - D[0]) + abs(C[1] - D[1]))
L.append(abs(C[0] - E[0]) + abs(C[1] - E[1]))
L.append(abs(C[0] - F[0]) + abs(C[1] - F[1]))
L.append(abs(C[0] - G[0]) + abs(C[1] - G[1]))
L.append(abs(C[0] - H[0]) + abs(C[1] - H[1]))
L.append(abs(D[0] - E[0]) + abs(D[1] - E[1]))
L.append(abs(D[0] - F[0]) + abs(D[1] - F[1]))
L.append(abs(D[0] - G[0]) + abs(D[1] - G[1]))
L.append(abs(D[0] - H[0]) + abs(D[1] - H[1]))
L.append(abs(E[0] - F[0]) + abs(E[1] - F[1]))
L.append(abs(E[0] - G[0]) + abs(E[1] - G[1]))
L.append(abs(E[0] - H[0]) + abs(E[1] - H[1]))
L.append(abs(F[0] - G[0]) + abs(F[1] - G[1]))
L.append(abs(F[0] - H[0]) + abs(F[1] - H[1]))
L.append(abs(G[0] - H[0]) + abs(G[1] - H[1]))
print(max(L))

Submission status: Wrong Answer

Solution code:
N = int(input())
ma = 0
mi = 10**18
for i in range(N):
    x,y = map(int,input().split())
    ma=max(ma,x+y)
    mi=min(mi,x+y)
print(ma-mi)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[0,0] for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    L[i][0]=a
    L[i][1]=b
L1=sorted(L, key=lambda x:x[0])
L2=sorted(L, key=lambda x:x[1])
ans1=abs(L1[0][0]-L2[0][0])+abs(L1[0][1]-L2[0][1])
ans2=abs(L1[-1][0]-L2[0][0])+abs(L1[-1][1]-L2[0][1])
ans3=abs(L1[0][0]-L2[-1][0])+abs(L1[0][1]-L2[-1][1])
ans4=abs(L1[0][0]-L2[-1][0])+abs(L1[0][1]-L2[-1][1])
print(max(ans1,ans2,ans3,ans4))

Submission status: Wrong Answer

Solution code:
n=int(input())
M_x,M_y,m_x,m_y=0,0,10**9,10**9
x_max,x_min,y_max,y_min=set(),set(),set(),set()
c=set()
mhd=lambda x,y: abs(x[0]-y[0])+abs(x[1]-y[1])
for i in range(n):
    x,y=map(int,input().split())
    if x==M_x: x_max.add((x,y))
    elif x>M_x:
        M_x=x
        x_max.clear()
        x_max.add((x,y))
    if x==m_x: x_min.add((x,y))
    elif x<m_x:
        m_x=x
        x_min.clear()
        x_min.add((x,y))
    if y==M_y: y_max.add((x,y))
    elif y>M_y:
        M_y=y
        y_max.clear()
        y_max.add((x,y))
    if y==m_y: y_min.add((x,y))
    elif y<m_y:
        m_y=y
        y_min.clear()
        y_min.add((x,y))
M=x_max|y_max
m=x_min|y_min
ca=[]
for c in M:
    for d in m: ca.append(mhd(c,d))
print(max(ca))

Submission status: Wrong Answer

Solution code:
import sys
import random

input = lambda : sys.stdin.readline().rstrip()

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

for i, (x, y) in enumerate(pairs):
    xy = x+y
    if i == 0:
        min_x = max_x = x
        min_y = max_y = y
        min_xi = [0]
        max_xi = [0]
        min_yi = [0]
        max_yi = [0]

        min_xyi = [0]
        max_xyi = [0]
        min_xy = max_xy = xy 
    else:
        if x < min_x:
            min_xi = [i]
            min_x = x
        elif x == min_x:
            min_xi.append(i)

        if y < min_y:
            min_yi = [i]
            min_y = y
        elif y == min_y:
            min_yi.append(i)

        if xy < min_xy:
            min_xyi = [i]
            min_xy = xy
        elif xy == min_xy:
            min_xyi.append(i)

        if x > max_x:
            max_xi = [i]
            max_x = x
        elif x == min_x:
            max_xi.append(i)

        if y > max_y:
            max_yi = [i]
            max_y = y
        elif y == min_y:
            max_yi.append(i)

        if xy > max_xy:
            max_xyi = [i]
            max_xy = xy
        elif xy == min_xy:
            max_xyi.append(i)



max_iter = 100

fmax_dist = -2
max_dist = -1

final_out = 0

#print("min_xi", min_xi, "min_yi", min_yi, "max_xi", max_xi, "max_yi", max_yi, "min_xyi", min_xyi, "max_xyi", max_xyi)
randoms = [random.randint(0, n-1) for i in range(3)]
first_jibuns = set(min_xi + max_xi + min_yi + max_yi + min_xyi + max_xyi + randoms)

True
for first_jibun in first_jibuns:
    jibun = first_jibun
    #for iter_i in range(max_iter):
    while True:
        jx, jy = pairs[jibun]
        for cur_aite in range(n):
            if jibun == cur_aite:
                continue
            ax, ay = pairs[cur_aite]
            cdist = abs(jx-ax) + abs(jy-ay)
            
            if cdist > max_dist:
                next_jibun = cur_aite
                max_dist = cdist

        if fmax_dist == max_dist:
            out = max_dist
            break

        jibun = next_jibun 
        fmax_dist = max_dist
    final_out = max(final_out, out)
    
    
print(final_out)

Submission status: Wrong Answer

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

a1=float('inf')
a2=0

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

print(a2-a1)

Submission status: Wrong Answer

Solution code:
def dist(v1, v2):
    return abs(v1[0]-v2[0]) + abs(v1[1]-v2[1])

def dist_not_abs(v1, v2):
    return (v1[0]-v2[0]) + (v1[1]-v2[1])

def main():
    N = int(input())
    v = []
    for i in range(N):
        vx, vy = map(int, input().split())
        v.append((vx, vy))

    if dist(v[0], (1, 1)) < dist(v[1], (1, 1)):
        left, right = v[0], v[1]
    else:
        left, right = v[1], v[0]

    for vi in v[2:]:
        if dist_not_abs(vi, right) > 0:
            right = vi
        elif dist_not_abs(vi, left) < 0:
            left = vi

    res = dist(right, left)
    print(res)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

max_x = 1 - (10 ** 9)
min_x = 2
max_y = 1 - (10 ** 9)
min_y = 2
for _ in range(n):
    x, y = map(int, input().split())
    s = x - y
    t = x + y
    
    max_x = max(max_x, s)
    min_x = min(min_x, s)
    max_y = max(max_y, t)
    min_y = min(min_y, t)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
z = []
for i in range(0,len(x)):
  z.append(x[i]+y[i])
max = max(z)
min = min(z)
print(abs(max-min))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from operator import itemgetter
def main():
    n = int(input())
    XY = [tuple(map(int,input().split())) for i in range(n)]
    XY.sort()
    ans = 0

    x_dl, y_dl = XY[0]
    for i in range(n):
        ans = max(ans, abs(XY[i][0]-x_dl)+abs(XY[i][1]-y_dl))
    XY.sort(reverse=True)
    x_dr, y_dr = XY[0]
    for i in range(n):
        ans = max(ans, abs(XY[i][0]-x_dr)+abs(XY[i][1]-y_dr))
    XY.sort(key = itemgetter(1))    
    x_ul, y_ul = XY[0]
    for i in range(n):
        ans = max(ans, abs(XY[i][0]-x_ul)+abs(XY[i][1]-y_ul))
    XY.sort(key = itemgetter(1),reverse=True) 
    x_ur, y_ur = XY[0]
    for i in range(n):
        ans = max(ans, abs(XY[i][0]-x_ur)+abs(XY[i][1]-y_ur))
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
max=0
for i in range(n):
  k,kk=map(int, input().split())
  m=l
  while(len(m)>0):
    h=m.pop()
    ma=abs(h[0]-k)+abs(h[1]-kk)
    if ma>max:
      max=ma
  l.append([k,kk])
print(max)

Submission status: Wrong Answer

Solution code:
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

A= []
N = int(input())
B= []
for i in range(N):
    a,b = ilele()
    A.append(a+b)
    B.append(a-b)
c = abs(min(A) - max(A))
d = abs(min(A) - max(A))
print(max(c,d))

Submission status: Wrong Answer

Solution code:
n=int(input())
D=0
d=10**9+1
for i in range(n):
    x,y=[int(x) for x in input().split()]
    l=x+y
    d=min(d,l)
    D=max(D,l)
print(D-d)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    z = sorted(sum(map(int,input().split())) for _ in range(N))
    return str(z[-1]-z[0])

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

minx = None
miny = None
maxx = None
maxy = None
p = [set(), set(), set(), set()]

for _ in range(n):
    x, y = map(int, input().split())
    if minx is None:
        minx = x
        maxx = x
        miny = y
        maxy = y
        for i in range(4):
            p[i] = {(x, y)}
        continue
    if x < minx:
        minx = x
        p[0] = {(x, y)}
    elif x == minx:
        p[0].add((x, y))
    if y < miny:
        miny = y
        p[1] = {(x, y)}
    elif y == miny:
        p[1].add((x, y))
    if x > maxx:
        maxx = x
        p[2] = {(x, y)}
    elif x == maxx:
        p[2].add((x, y))
    if y > maxy:
        maxy = y
        p[3] = {(x, y)}
    elif y == maxy:
        p[3].add((x, y))

p = list(itertools.chain.from_iterable(p))
ans = 0
for q, s in itertools.combinations(p, 2):
    ans = max(ans, abs(s[0] - q[0]) + abs(s[1] - q[1]))
print(ans)