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:
import itertools

n = int(input())

minx = None
miny = None
maxx = None
maxy = None
p = [None] * 4

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)
    if y < miny:
        miny = y
        p[1] = (x, y)
    if x > maxx:
        maxx = x
        p[2] = (x, y)
    if y > maxy:
        maxy = y
        p[3] = (x, y)

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

Submission status: Wrong Answer

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

import numpy as np

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

xy = [i+j for i, j in x_y]

ans1 = max(xy)-min(xy)

xy_rev = [i/j for i, j in x_y]


min_index = np.argmin(xy_rev)
max_index = np.argmax(xy_rev)

x1, y1 = x_y[max_index]
x2, y2 = x_y[min_index]

ans2 = abs(x2-x1)+abs(y2-y1)

print(max(ans1, ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
x1, y1 = map(int, input().split())
centre = [x1, y1]

left_bottom = [x1, y1]
left_bottom_dist = 0

left_top = [x1, y1]
left_top_dist = 0

right_bottom = [x1, y1]
right_bottom_dist = 0

right_top = [x1, y1]
right_top_dist = 0

for i in range(N-1):
  xi, yi = map(int, input().split())
  if xi <= x1 and yi <= y1:
    if x1 - xi + y1 - xi >= left_bottom_dist:
      left_bottom = [xi, yi]
      left_bottom_dist = x1 - xi + y1 - xi
  if xi <= x1 and yi >= y1:
    if x1 - xi + yi - y1 >= left_top_dist:
      left_top = [xi, yi]
      left_top_dist = x1 - xi + yi - y1
  if xi >= x1 and yi <= y1:
    if xi - x1 + y1 - yi >= right_bottom_dist:
      right_bottom = [xi, yi]
      right_bottom_dist = xi - x1 + y1 - yi 
  if xi >= x1 and yi >= y1:
    if xi - x1 + yi - y1 >= right_top_dist:
      right_top = [xi, yi]
      right_top_dist = xi - x1 + yi - y1

D1 = right_top[0] - left_bottom[0] + right_top[1] - left_bottom[1]
D2 = right_bottom[0] - left_top[0] + left_bottom[1] - right_top[1]
D3 = abs(left_top[0] - left_bottom[0]) + abs(left_top[1] - left_bottom[1])
D4 = abs(right_top[0] - right_bottom[0]) + abs(right_top[1] - right_bottom[1])
D5 = abs(left_top[0] - right_top[0]) + abs(left_top[1] - right_top[1])
D6 = abs(left_bottom[0] - right_bottom[0]) + abs(left_bottom[1] - right_bottom[1])

print(max(D1, D2, D3, D4, D5, D6))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [None]*n
y = [None]*n

for i in range(n):
    x[i],y[i] = map(int,input().split())
    
d_from0 = 0
p_far = 0
x_0 = x[0]
y_0 = y[0]

for i in range(n):
    d = abs(x[i]-x_0)+abs(y[i]-y_0)
    if d > d_from0:
        d_from0 = d
        p_far = i

x_p = x[p_far]
y_p = y[p_far]

ans = 0

for i in range(n):
    d = abs(x[i]-x_p)+abs(y[i]-y_p)
    if d > ans:
        ans = d
print(ans)

Submission status: Wrong Answer

Solution code:
INF=10**6
n=int(input())
f=lambda:map(int,input().split())
s_min=t_min=INF
s_max=t_max=-INF
for _ in range(n):
  x,y=f()
  s_min=min(s_min,x+y)
  s_max=max(s_max,x+y)
  t_min=min(t_min,x-y)
  t_max=max(t_max,x-y)
print(max(s_max-s_min,t_max-t_min))

Submission status: Wrong Answer

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


def maximize(ps):
    zs = sorted(x + y for x, y in ps)
    return abs(zs[0] - zs[-1])


def main():
    n = int(input())
    ps = []
    for _ in range(n):
        ps.append(tuple(int(z) for z in input().split()))
    res = maximize(ps)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
m = 2*(10**9)+1
M = 0
for i in range(N):
  a,b = map(int,input().split())
  temp = a+b
  m = min(m,temp)
  M = max(M,temp)
print(M-m)

Submission status: Wrong Answer

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(int(max(max(xy0)-min(xy1),max(xy1)-min(xy0))/2))

Submission status: Wrong Answer

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

N = int(input())
xy = []
for _ in range(N):
    x, y = map(int, input().split())
    xy.append([x, y])

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

ans = abs(xy[0][0] - xy[-1][0]) + abs(xy[0][1] - xy[-1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

L1=[]
L2=[]
L3=[]
L4=[]
for x,y in P:
    L1.append(x+y)
    L2.append(-x+y)
    L3.append(x-y)
    L4.append(-x-y)

L1=sorted(L1)
L2=sorted(L1)
L3=sorted(L1)
L4=sorted(L1)

ans=max(L1[-1]-L1[0],L2[-1]-L2[0],L3[-1]-L3[0],L4[-1]-L4[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
C = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    C[i] = (x + y, x, y)
C = sorted(C)
# a1, x1, y2 = C[-1]
# print(C)
ans = abs(C[-1][1] - C[0][1]) + abs(C[-1][2] - C[0][2])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(grid):  # fix inputs here
    console("----- solving ------")

    # return a string (i.e. not a list or matrix)
    return max(max([(x+y) for x,y in grid]) - min([(x+y) for x,y in grid]), 
               max([(x-y) for x,y in grid]) - min([(x+y) for x,y in grid]))


def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
inp = sys.stdin.readlines()

for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    nrows = int(inp[0])
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    # lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    grid = []
    for row in range(1,nrows+1):
        grid.append(list(map(int,inp[row].split())))

    res = solve(grid)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)

Submission status: Wrong Answer

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

print(max(max(xy_1) - min(xy_1), max(xy_2)))

Submission status: Wrong Answer

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)]

    dist = []
    for i in range(n):
        x, y = XY[i]
        dist.append([x + y, XY[i]])
    dist.sort()
    res = dist[-1][1][0] - dist[0][1][0] + dist[-1][1][1] - dist[0][1][1]
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
XY=[list(map(int,input().split())) for i in range(n)]
minxy = [XY[0][0],XY[0][1]]
maxxy = [XY[0][0],XY[0][1]]
for xy in XY:
  if xy[0]+xy[1] < sum(minxy):
    minxy = xy[0],xy[1]
  if xy[0]+xy[1] > sum(maxxy):
    maxxy = xy[0],xy[1]
print(abs(minxy[0]-maxxy[0])+abs(minxy[0]-maxxy[1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[]
for i in range(n):
    l.append(list(map(int,list(input().split()))))
l.sort()
c=0
print(l)
for i in range(1,n):
    t = abs(l[i][0]-l[0][0])+abs(l[i][1]-l[0][1])
    if t>c:
        c=t
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
x, y = map(int, input().split())
A = B = C = D = [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]
L1 = abs(A[0] - B[0]) + abs(A[1] - B[1])
L2 = abs(A[0] - C[0]) + abs(A[1] - C[1])
L3 = abs(A[0] - D[0]) + abs(A[1] - D[1])
L4 = abs(B[0] - C[0]) + abs(B[1] - C[1])
L5 = abs(B[0] - D[0]) + abs(B[1] - D[1])
L6 = abs(C[0] - D[0]) + abs(C[1] - D[1])
L = max([L1, L2, L3, L4, L5, L6])
print(L)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans = [None] * N
for i in range(N):
    ans[i] = xy[i][0] + xy[i][1]
ans.sort()
print(ans[-1]-ans[0])

Submission status: Wrong Answer

Solution code:

n = int(raw_input())
points = set([])
for _ in range(n):
	p = map(int, raw_input().split())
	points.add(tuple(p))
points = list(points)
def distance(p,q): return abs(p[0] - q[0]) + abs(p[1] - q[1])


def f(points):
	r = 0
	pss = []
	for u in [-1,1]:
		for v in [-1,1]: 	
			pss.append(max(points, key = lambda x:(u*x[0],v*x[1])))
	for p in pss:
		for q in points: r = max(r, distance(p,q))
	return r
print f(points)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(stdin.readline().strip())
min_a = float("inf")
min_s = (0,0)
max_a = 0
max_s = (0,0)
for _ in range(N):
    x,y = map(int,stdin.readline().strip().split())
    manhat = x+y
    if manhat < min_a:
        min_s = (x,y)
        min_a = manhat
    elif manhat > max_a:
        max_a = manhat
        max_s = (x,y)
print(abs(max_s[0]-min_s[0])+abs(max_s[1]-min_s[1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[]
s=set()
for _ in range(n):
	x,y=map(int,input().split())
	if((x,y) not in s):
		arr.append(x+y)
		s.add((x,y))
arr.sort()
if(len(arr)==1):
	print(0)
else:
	print(arr[-1]-arr[0])

Submission status: Wrong Answer

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    n = inp()
    q = 0
    w = 1000000000000000000000000000
    for i in range(n):
        x,y = invr()
        q = max(q,x + y)
        w = min(w,x + y)
    print(q - w)
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)

#-----------------------------------------------------------------------#
        
  
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Submission status: Wrong Answer

Solution code:
def cin():  return list(map(int,input().split()))

N = cin()[0]
x = []
for i in range(N): x.append(cin())

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

xx = sorted(x, key = lambda x: x[0])
ans1 = 0
for i in range(N):
    res = dis(xx[0][0], xx[0][1], xx[i][0], xx[i][1])
    ans1 = max(ans1, res)
for i in range(N):
    res = dis(xx[-1][0], xx[-1][1], xx[i][0], xx[i][1])
    ans1 = max(ans1, res)
    
yy = sorted(x, key = lambda x: x[1])
ans2 = 0
for i in range(N):
    res = dis(yy[0][0], yy[0][1], yy[i][0], yy[i][1])
    ans2 = max(ans2, res)
for i in range(N):
    res = dis(yy[-1][0], yy[-1][1], yy[i][0], yy[i][1])
    ans2 = max(ans2, res)
    
ans = max(ans1, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())


mm = 10**12
mx = 0

for _ in range(n):
    x, y = map(int, input().split())

    mm = min(mm, x+y)
    mx = max(mx, x+y)

print(mx-mm)

Submission status: Wrong Answer

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

x = abs(dots[dots_sum.index(min(dots_sum))][0] - dots[dots_sum.index(max(dots_sum))][0])
y = abs(dots[dots_sum.index(min(dots_sum))][1] - dots[dots_sum.index(max(dots_sum))][1])

print(x + y)

Submission status: Wrong Answer

Solution code:
n=int(input())
s,p=10**9+1,10**9+1
t,q=-1,-1

for i in range(n):
  x,y=map(int,input().split())
  s=min(s,x+y)
  t=max(t,x+y)
  p=min(p,x-y)
  q=max(q,x-y)
  
print(max(t-s,q-p))

Submission status: Wrong Answer

Solution code:
n = int(input())
maxx = 0
minn = 2000000001
for i in range(n):
    x,y = map(int,input().split())
    minn = min(minn,x+y)
    maxx = max(maxx,x+y)
print(maxx-minn)

Submission status: Wrong Answer

Solution code:
N=int(input())

XY=[]
for i in range(N):
    x,y=input().split()
    XY.append((int(x),int(y)))
    
Md=[]

for s in range(N):
    for t in range(N):
        d=abs(XY[s][0])-abs(XY[t][0])+abs(XY[s][1])-abs(XY[t][1])
        Md.append(d)

print(max(Md))

Submission status: Wrong Answer

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

xy1 = sorted(xy, key=lambda x: x[0])
xy2 = sorted(xy, key=lambda x: x[1])
# print(xy1)
# print(xy2)
dist1 = abs(xy1[0][0] - xy1[-1][0]) + abs(xy1[0][1] - xy1[-1][1])
dist2 = abs(xy2[0][0] - xy2[-1][0]) + abs(xy2[0][1] - xy2[-1][1])
ans = max(dist1, dist2)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools  import product
def dist(p, q):
    return abs(p[0] - q[0]) + abs(p[1] - q[1])

n = int(input())
P = [tuple(map(int, input().split())) for _ in range(n)]
peri = []
P.sort()
peri.append(P[0])
peri.append(P[-1])
ans = dist(P[0], P[-1])
P.sort(key=lambda p: (p[0], -p[1]))
peri.append(P[0])
peri.append(P[-1])
P.sort(key=lambda p: (p[1], p[0]))
peri.append(P[0])
peri.append(P[-1])
P.sort(key=lambda p: (p[1], -p[0]))
peri.append(P[0])
peri.append(P[-1])

peri = set(peri)
ans = max(dist(p, q) for p, q in product(peri, repeat=2))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x,y = map(int,input().split(" "))
papb = [x,y]
pamb = [x,y]
mapb = [x,y]
mamb = [x,y]
for i in range(N - 1):
    x,y = map(int,input().split(" "))
    if x + y > papb[0] + papb[1]:papb = [x,y]
    if x - y > pamb[0] + pamb[1]:pamb = [x,y]
    if 0 - x + y > mapb[0] + mapb[1]:mapb = [x,y]
    if 0 - x - y > mamb[0] + mamb[1]:mamb = [x,y]
print(max(abs(papb[0] - mamb[0]) + abs(papb[1] - mamb[1]),abs(pamb[0] - mapb[0]) + abs(pamb[1] - mapb[1])))

Submission status: Wrong Answer

Solution code:
minn=10**18
maxx=-10**18
for _ in range(input()):
    x,y=[int(i)+10**9 for i in raw_input().split()]
    minn=min(minn,x+y)
    maxx=max(maxx,x+y)
print maxx-minn

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

ans = 0
point_1 = point[0]
point_2 = point[1]
dist = calc(point_1, point_2)
for i in range(n - 2):
    point_3 = point[i + 2]
    dist_13 = calc(point_1, point_3)
    dist_23 = calc(point_2, point_3)
    if (dist_13 > dist_23) & (dist_13 > dist):
        dist = dist_13
        point_2 = point_3
        continue
    elif (dist_23 > dist_13) & (dist_23 > dist):
        dist = dist_23
        point_1 = point_3
        continue
ans = max(ans, dist)        
point.sort(key=lambda x: x[1])
point_1 = point[0]
point_2 = point[1]
dist = calc(point_1, point_2)
for i in range(n - 2):
    point_3 = point[i + 2]
    dist_13 = calc(point_1, point_3)
    dist_23 = calc(point_2, point_3)
    if (dist_13 > dist_23) & (dist_13 > dist):
        dist = dist_13
        point_2 = point_3
        continue
    elif (dist_23 > dist_13) & (dist_23 > dist):
        dist = dist_23
        point_1 = point_3
        continue
ans = max(ans, dist)        
        
print(ans)

Submission status: Wrong Answer

Solution code:
import random

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

S = set()
for i in range(N):
  S.add((x[i], y[i]))
S = sorted(list(S))

ans = 0
for i in range(6):
  if i==0:
    o = 0
  elif i==1:
    o = len(S)-1
  else:
    o = random.randint(0, len(S)-1)
  m = 0
  mp = 0
  for i in range(N):
    d = abs(x[i]-S[o][0])+abs(y[i]-S[o][1])
    if d>m:
      m = d
      mp = i
  for i in range(N):
    ans = max(ans, abs(x[i]-x[mp])+abs(y[i]-y[mp]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
xy = tuple(map(int, input().split()))
M = sum(xy)
Mxy = xy
m = M
mxy = xy
for _ in range(n - 1):
    xy = tuple(map(int, input().split()))
    s = sum(xy)
    if s > M:
        M = s
        Mxy = xy
    if s < m:
        m = s
        mxy = xy
print(abs(Mxy[0]-mxy[0])+abs(Mxy[1]-mxy[1]))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a,b=0,0
c,v,b,m=0,0,0,0
for i in range(n):
    x,y=map(int,input().split())
    c=max(x+y,c)
    if i==0:
        v=x+y
    else:
        v=min(x+y,v)

   
    if math.fabs(x-y)>b:
        m=b
    b=max(b,math.fabs(x-y))
print(int(max(c-v, m+b)))

Submission status: Wrong Answer

Solution code:

n = int(raw_input())
points = set([])
for _ in range(n):
	p = map(int, raw_input().split())
	points.add(tuple(p))
points = list(points)
def distance(p,q): return abs(p[0] - q[0]) + abs(p[1] - q[1])


def f(points):
	r = 0
	
	p = max(points, key = lambda x:x[0])
	for q in points: r = max(r, distance(p,q))
	
	p = max(points, key = lambda x:x[1])
	for q in points: r = max(r, distance(p,q))
	
	p = max(points, key = lambda x:-x[1])
	for q in points: r = max(r, distance(p,q))

	p = max(points, key = lambda x:-x[0])
	for q in points: r = max(r, distance(p,q))
	
	return r
print f(points)

Submission status: Wrong Answer

Solution code:
x = input()

max = 0
min = 99999

for _ in range(int(x)):
 a = input()
 ax = int(a.split()[0])
 ay = int(a.split()[1])
# l = (ax*ax + ay*ay)**0.5
 l = (ax*1 + ay*1)**1
# print(l)
 if l > max: 
  max = l
 if l < min:
  min = l

# a<x<b, c<y<d
# manhatan = max - min
#print("manha")
print( max - min)

# bd, ac, ad, bc

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = int(sys.stdin.readline().rstrip())

    X = [None] * N
    Y = [None] * N 
    Z = [None] * N

    for i in range(N):
        x, y = map(int, sys.stdin.readline().rstrip().split())
        X[i] = x
        Y[i] = y
    
    X_min = min(X)
    Y_min = min(Y)

    for i in range(N):
        X[i] = X[i] - X_min
        Y[i] = Y[i] - Y_min
        Z[i] = X[i] + Y[i]

    print(max(Z) - min(Z))


main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline

n = int(input())
INF = 1 << 35
M = -INF
m = INF

for i in range(n):
    x, y = map(int, input().split())
    a = x - y
    b = x + y
    if a > b:
        a, b = b, a
    M = max(M, b)
    m = min(m, b)
print(M - m)

Submission status: Wrong Answer

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

def main():
    N = int(input())
    o = (1, 1)
    v = []
    min_dist = 1000000
    min_dist_index = 0
    for i in range(N):
        vx, vy = map(int, input().split())
        v.append((vx, vy))
        if min_dist > dist(o, (vx, vy)):
            min_dist = dist(o, (vx, vy))
            min_dist_index = i

    m = v[min_dist_index]

    max_dist = 0
    for vi in v:
        if max_dist < dist(m, vi):
            max_dist = dist(m, vi)

    print(max_dist)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
for _ in range(n):
    x,y = map(int,input().split())
    xy.append((x,y))
    
al,be = 1000000000,1000000000

man = []
for i,j in xy:
    man.append((al-i) + (be-j))
    
print(max(man) - min(man))

Submission status: Wrong Answer

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

print(memo[-1]-memo[0])

Submission status: Wrong Answer

Solution code:
def cin():  return list(map(int,input().split()))

N = cin()[0]
x = []
for i in range(N): x.append(cin())

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

xx = sorted(x, key = lambda x: x[0])
ans1 = 0
for i in range(N):
    res = dis(xx[0][0], xx[0][1], xx[i][0], xx[i][1])
    ans1 = max(ans1, res)
    
yy = sorted(x, key = lambda x: x[1])
ans2 = 0
for i in range(N):
    ans2 = dis(yy[0][0], yy[0][1], yy[i][0], yy[i][1])
    ans1 = max(ans2, res)
    
ans = max(ans1, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
d=[x+y for x,y in xy]
d.sort()
ans=d[-1]-d[0]
maxy=max([y for x,y in xy])
dr=[x+(maxy-y) for x,y in xy]
ans=max(ans,dr[-1]-dr[0])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
t=10**9*2
k=0
for i in range(N):
    a,b=map(int,input().split())
    t=min(t,a+b)
    k=max(k,a+b)
print(k-t)

Submission status: Wrong Answer

Solution code:
import random

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

S = set()
for i in range(N):
  S.add((x[i], y[i]))
S = list(S)

ans = 0
for i in range(6):
  o = random.randint(0, len(S)-1)
  m = 0
  mp = 0
  for i in range(N):
    d = abs(x[i]-S[o][0])+abs(y[i]-S[o][1])
    if d>m:
      m = d
      mp = i
  for i in range(N):
    ans = max(ans, abs(x[i]-x[mp])+abs(y[i]-y[mp]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import combinations
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    point_x = []
    point_y = []
    for _ in range(N):
        x, y = map(int, input().split())
        point_x.append((x, y))
        point_y.append((y, x))
    point_x.sort()
    point_y.sort()
    x_min = []
    x_max = []
    y_min = []
    y_max = []
    for pt in point_x:
        if pt[0] != point_x[0][0]: break
        x_min.append(pt)
    for pt in point_x[::-1]:
        if pt[0] != point_x[-1][0]: break
        x_max.append(pt)
    for pt in point_y:
        if pt[0] != point_y[0][0]: break
        y_min.append((pt[1], pt[0]))
    for pt in point_y[::-1]:
        if pt[0] != point_y[-1][0]: break
        y_max.append((pt[1], pt[0]))

    x_min = [x_min[0], x_min[-1]]
    x_max = [x_max[0], x_max[-1]]
    y_min = [y_min[0], y_min[-1]]
    y_max = [y_max[0], y_max[-1]]

    cand = x_min + x_max + y_min + y_max
    ans = 0
    for pt1, pt2 in combinations(cand, 2):
        ans = max(ans, abs(pt1[0] - pt2[0]) + abs(pt1[1] - pt2[1]))
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[]
for _ in range(n):
    a,b=map(int,input().split())
    r.append([a+b,[a,b]])
r=sorted(r,reverse=True,key=lambda x:x[0])
print(abs(r[0][1][0]-r[-1][1][0])+abs(r[0][1][1]-r[-1][1][1]))

Submission status: Wrong Answer

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

def main():
    n = int(input())
    p = [list(map(int, input().split())) for i in range(n)]
    max_p = [0] * 2
    for i in range(n):
        a, b = p[i][0], p[i][1]
        if max_p[0]**2 + max_p[1]**2 < a**2 + b**2:
            max_p[0], max_p[1] = a, b
    ans = 0
    for i in range(n):
        tmp = abs(max_p[0] - p[i][0]) + abs(max_p[1] - p[i][1])
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
t=10**9
k=0
for i in range(N):
    a,b=map(int,input().split())
    t=min(t,a+b)
    k=max(k,a+b)
print(k-t)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

point_1 = point[0]
point_2 = point[1]
dist = calc(point_1, point_2)
for i in range(n - 2):
    point_3 = point[i + 2]
    dist_13 = calc(point_1, point_3)
    dist_23 = calc(point_2, point_3)
    if (dist_13 > dist_23) & (dist_13 > dist):
        dist = dist_13
        point_2 = point_3
        continue
    elif (dist_23 > dist_13) & (dist_23 > dist):
        dist = dist_23
        point_1 = point_3
        continue
print(dist)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
Y=[]

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

dp=[-1]*N #点iと他の点との間で最長のマンハッタン距離を格納。

a=min(X)
b=max(X)
c=min(Y)
d=max(Y)

for i in range(N):
    if dp[i]!=-1:
        continue
    if a < X[i] < b and c < Y[i] < d:
        continue
    dist=0
    ind=-1
    for j in range(i+1,N):
        tmp = abs(X[i]-X[j])+abs(Y[i]-Y[j])
        if dist < tmp:
            dist = tmp
            ind = j
    dp[i]=dist
    dp[j]=dist
print(max(dp))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
C = [list(map(int,input().split())) for i in range(n)]

a = 10**9 + 5
b = -1
c = 10**9 + 5
d = -1
for i in range(n):
    a = min(a, C[i][0])
    b = max(b, C[i][0])
    c = min(c, C[i][1])
    d = max(d, C[i][1])

A = [[] for i in range(4)]
B = [a,b,c,d]
for i in range(n):
    for j in range(2):
        if C[i][0] == B[j]:
            A[j].append(C[i])
        if C[i][1] == B[j+2]:
            A[j+2].append(C[i])

A[0].sort(key=lambda x:x[1])
A[1].sort(key=lambda x:x[1])
A[2].sort(key=lambda x:x[0])
A[3].sort(key=lambda x:x[0])

def mnh(a,b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])

ans = 0
for i in range(len(A[0])):
    if len(A[1]) > 0:
        ans = max(ans, mnh(A[0][i], A[1][0]), mnh(A[0][i], A[1][-1]))
    if len(A[2]) > 0:
        ans = max(ans, mnh(A[0][i], A[2][-1]))
    if len(A[3]) > 0:
        ans = max(ans, mnh(A[0][i], A[3][-1]))

for i in range(len(A[1])):
    if len(A[0]) > 0:
        ans = max(ans, mnh(A[1][i], A[0][0]), mnh(A[1][i], A[0][-1]))
    if len(A[2]) > 0:
        ans = max(ans, mnh(A[1][i], A[2][0]))
    if len(A[3]) > 0:
        ans = max(ans, mnh(A[1][i], A[3][0]))

for i in range(len(A[2])):
    if len(A[3]) > 0:
        ans = max(ans, mnh(A[2][i], A[3][0]), mnh(A[2][i], A[3][-1]))
    if len(A[0]) > 0:
        ans = max(ans, mnh(A[2][i], A[0][-1]))
    if len(A[1]) > 0:
        ans = max(ans, mnh(A[2][i], A[1][-1]))

for i in range(len(A[3])):
    if len(A[2]) > 0:
        ans = max(ans, mnh(A[3][i], A[2][0]), mnh(A[3][i], A[2][-1]))
    if len(A[0]) > 0:
        ans = max(ans, mnh(A[3][i], A[0][0]))
    if len(A[1]) > 0:
        ans = max(ans, mnh(A[3][i], A[1][0]))

print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
kyori = []
for i in range(N):
    tmp1 = xy[i][0] + xy[i][1]
    tmp2 = abs(xy[i][0] - xy[i][1])
    kyori.append((i, tmp1, tmp2))


kyori.sort(key=lambda x: (x[1], x[2]))
print(abs(xy[kyori[0][0]][0] - xy[kyori[-1][0]][0]) + abs(xy[kyori[0][0]][1] - xy[kyori[-1][0]][1]))

Submission status: Wrong Answer

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
points = set()
for _ in xrange(n):
    x,y = (int(x) for x in input().split())
    points.add((x,y))

if len(points) <= 1:
    print(0)
else:
    srt = sorted(points, key=lambda x: x[0] + x[1])
    x1,y1 = srt[0]
    x2,y2 = srt[-1]
    print(abs(x1+y1 - (x2+y2)))

Submission status: Wrong Answer

Solution code:
N = int(input())

dists = []
while N:
    x, y = map(int, input().split())
    dists.append((x, y, x+y))
    N -= 1

dists.sort(key=lambda x: x[2])
print(abs(dists[0][0] - dists[-1][0]) + abs(dists[0][1] - dists[-1][1]))