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

p = []

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

max_x = max(p, key=lambda a: a[0])[0]
max_y = max(p, key=lambda a: a[0])[1]
min_x = min(p, key=lambda a: a[0])[0]
min_y = min(p, key=lambda a: a[0])[1]
xy = max(p, key=lambda a: a[0] + a[1])
max_xy = sum(xy)
xy = min(p, key=lambda a: a[0] + a[1])
min_xy = sum(xy)

x = []
x.append([a for a in p if a[0] == max_x])
x.append([a for a in p if a[0] == min_x])
x.append([a for a in p if a[1] == max_y])
x.append([a for a in p if a[1] == min_y])
x.append([a for a in p if a[0] + a[1] == max_xy])
x.append([a for a in p if a[0] + a[1] == min_xy])

ans = 0
z = []
for c in x:
    for d in c:
        z.append(d)
for i in range(len(z) - 1):
    for j in range(i+1, len(z)):
        e = abs(z[i][0] - z[j][0]) + abs(z[i][1] - z[j][1])
        ans = max(ans, e)

print(ans)

Submission status: Wrong Answer

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

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

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

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())
p = []
for _ in range(N):
    x, y = map(int, input().split())
    p.append((x, y))
px = sorted(p, key=lambda i: i[0] + i[1])
py = sorted(p, key=lambda i: abs(i[0] - i[1]))
print(max(abs(sum(px[0]) - sum(px[-1])), abs(sum(py[0]) - sum(py[-1]))))

Submission status: Wrong Answer

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

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

N = cin()[0]
v = []
INF = 10 ** 9 + 7
for i in range(N): v.append(cin())

xx = sorted(v, key = lambda x: x[0])
min_x = xx[0][0]
max_x = xx[-1][0]
yy = sorted(v, key = lambda x: x[1])
min_y = yy[0][1]
max_y = yy[-1][1]

kkk = [[min_x, 0], [min_x, INF], [max_x, 0], [max_x, INF], [0, min_y], [INF, min_y], [0, max_y,], [INF, max_y]]

a = []
b = []
c = []
d = []
for i in range(N):
    if v[i][0] == min_x:
        a.append(v[i][1])
    if v[i][0] == max_x:
        b.append(v[i][1])
    if v[i][1] == min_y:
        c.append(v[i][0])
    if v[i][1] == max_y:
        d.append(v[i][0])

kkk[0][1] = min(a)
kkk[1][1] = max(a)
kkk[2][1] = min(b)
kkk[3][1] = max(b)
kkk[4][0] = min(c)
kkk[5][0] = max(c)
kkk[6][0] = min(d)
kkk[7][0] = max(d)

ans3 = 0
for i in range(8):
    for j in range(N):
        res = dis(kkk[i][0], kkk[i][1], v[j][0], v[j][1])
        ans3 = max(res, ans3)

print(ans3)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
p1=min(l)
p2=max(l)
p3=min([l[i][::-1] for i in range(n)])
p4=max([l[i][::-1] for i in range(n)])
def f(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])
ans=0
for i in l:
    ans=max(ans,f(i,p1))
    ans = max(ans,f(i, p2))
    ans = max(ans,f(i, p3))
    ans = max(ans,f(i, p4))
print(ans)

Submission status: Wrong Answer

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


class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y


def Left_index(points):
    minn = 0
    for i in range(1, len(points)):
        if points[i].x < points[minn].x:
            minn = i
        elif points[i].x == points[minn].x:
            if points[i].y > points[minn].y:
                minn = i
    return minn


def orientation(p, q, r):
    val = (q.y - p.y) * (r.x - q.x) - \
          (q.x - p.x) * (r.y - q.y)

    if val == 0:
        return 0
    elif val > 0:
        return 1
    else:
        return 2


def convexHull(points, n):
    # There must be at least 3 points
    if n < 3:
        return

    # Find the leftmost point
    l = Left_index(points)

    hull = []

    p = l
    q = 0
    while (True):

        # Add current point to result
        hull.append(p)
        q = (p + 1) % n

        for i in range(n):

            # If i is more counterclockwise
            # than current q, then update q
            if (orientation(points[p],
                            points[i], points[q]) == 2):
                q = i
        p = q

        # While we don't come to first point
        if (p == l):
            break

    # Print Result
    ans=[]
    for each in hull:
        ans.append((points[each].x,points[each].y))
    return ans

n=int(input())
points = []
for _ in range(n):
    a,b=inpt()
    points.append(Point(a,b))
ans=convexHull(points, len(points))
#print(ans)
res=0
if(not ans):
    print(0)
    exit()
for i in range(len(ans)):
    a,b=ans[i]
    for j in range(i+1,len(ans)):
        c,d=ans[j]
        res=max(res,abs(a-c)+abs(b-d))
print(res)


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

Solution code:
def man_dist(p1, p2):
    return abs(p1[0]-p2[0]) + abs(p1[1]-p2[1])

# print('input >>')
N = int(input())
xys = []
for _ in range(N):
    xys.append(tuple(map(int,(input().split()))))

xys_x = sorted(xys, key=lambda xy: xy[0])
xys_y = sorted(xys, key=lambda xy: xy[1])

x_min = xys_x[0][0]
x_max = xys_x[-1][0]
y_min = xys_y[0][1]
y_max = xys_y[-1][1]

cand = [xy for xy in xys if xy[0] == x_min or xy[0] == x_max or xy[1] == y_max or xy[1] == y_min]

ans = 0

for c1 in cand:
    for c2 in cand:
        ans = max(ans, man_dist(c1, c2))

# print('-----output-----')
print(ans)

Submission status: Wrong Answer

Solution code:
import math as mt
import sys
import bisect
input=sys.stdin.readline
#t=int(input())
t=1

mod=10**9+7
for _ in range(t):
    
    n=int(input())
    l=[]
    for i in range(n):
        x,y=map(int,input().split())
        l.append(x+y)
    
    #u1,d1=map(int,input().split())
    #u2,d2=map(int,input().split())
    #l=list(map(int,input().split()))
    l.sort()
    print(l[-1]-l[0])

Submission status: Wrong Answer

Solution code:
from collections import deque
def dist(A,B):
    return abs(A[0]-B[0])+abs(A[1]-B[1])

N=int(input())
P=[0]*N

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

I=0
M=-1
for i in range(N):
    if M<dist(P[0],P[i]):
        I=i
        M=dist(P[0],P[i])

J=0
M=-1
for j in range(N):
    if M<dist(P[I],P[j]):
        J=j
        M=dist(P[I],P[j])

print(dist(P[I],P[J]))

Submission status: Wrong Answer

Solution code:
from sys import stdin

readline = stdin.readline

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

xy.sort()

c = set(xy[:1000])
c = c | set(xy[-1000:])

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

c = c | set(xy[:1000])
c = c | set(xy[-1000:])

c = list(c)
result = 0
for i in range(len(c)):
    for j in range(i + 1, len(c)):
        result = max(result, abs(c[i][0] - c[j][0]) + abs(c[i][1] - c[j][1]))
print(result)

Submission status: Wrong Answer

Solution code:
def dist(a,b):
  d = a - b
  if d < 0:
    return -(d)
  else:
    return d
def max_dist(a_list,b_list):
  max_d = dist(a_list[0], b_list[-1])
  for a in a_list:
    for b in b_list:
      d = dist(a,b)
      if d > max_d:
        max_d = d
  return max_d
N = int(input())
dict = {}
x_list = [0 for i in range(N)]
y_list = [0 for i in range(N)]
for i in range(N):
  x,y = map(int,input().split())
  x_list[i] = x
  y_list[i] = y
  if x not in dict:
    dict[x] = [y]
  else:
    dict[x].append(y)
if len(dict) == 1:
  y = dict[x]
  y = set(y)
  if len(y) == 1:
    print(0)
  else:
    y = dict[x]
    y.sort()
    result = dist(y[0], y[-1])
    print(result)
else:
  result = dist(x_list[0],dict[x][0])
  for i in range(N):
    xi = x_list[i]
    yi_list = dict[xi]
    yi_list.sort()
    for j in range(N-i):
      xj = x_list[i+j]
      yj_list = dict[xj]
      yj_list.sort()
      max_i = dist(yi_list[0], yi_list[-1])
      max_j = dist(yj_list[0], yj_list[-1])
      if max_i > result:
        result = max_i
      if max_j > result:
        result = max_j
      max_ij = dist(xi,xj) + max_dist(yi_list, yj_list)
      if max_ij > result:
         result = max_ij
  print(result)

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], x[1]))
L2=sorted(L, key=lambda x:(x[1], x[0]))
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:
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

x0 = 10 ** 9
y0 = 10 ** 9

d = x0 + y0

M = 0
m = 4 * d + 1
for x, y in XY:
    p = x + y + d
    if p > M:
        M = p
    if p < m:
        m = p

# print(M, m)

print(M - m)

Submission status: Wrong Answer

Solution code:
import random

n = int(input())
xys = []
for _ in range(n):
    x, y = input().split(" ")
    xys.append([int(x), int(y)])
    #xys.append([random.randint(-1000,1000), random.randint(-1000,1000)])


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


p_a = xys[0]
p_b = xys[1]
for _ in range(3):
    random.shuffle(xys)
    for p_c in xys:
        d_a_b = m(p_a, p_b)
        d_a_c = m(p_a, p_c)
        d_b_c = m(p_b, p_c)

        if d_a_b > max(d_a_c, d_b_c):
            pass
        else:
            if d_a_c > d_b_c:
                p_b = p_c
            else:
                p_a = p_c
print(m(p_a, p_b))

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
x1 = 0
y1 = 0
for _ in range(N):
    x, y = map(int, input().split())
    xy.append([x, y])
    if abs(x) + abs(y) > abs(x1) + abs(y1):
        x1 = x
        y1 = y
ans = 0
for x, y in xy:
    ans = max(ans, abs(x1 - x) + abs(y1 - y))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

P = []

for _ in range(N):
    x, y = [int(n) for n in input().split(" ")]
    P.append([x, y])


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


def getLengest(nowIndex, points):
    maxscore = 0
    maxIndex = -1

    for i in range(N):
        if i != nowIndex:
            ll = getMan(points[nowIndex], points[i])
            if maxscore <= ll:
                maxscore = ll
                maxIndex = i

    return maxIndex, maxscore


now = 0
already = [now]
while True:
    nextIndex, score = getLengest(now, P)
    if nextIndex in already:
        print(score)
        break
    else:
        already.append(nextIndex)
    now = nextIndex

Submission status: Wrong Answer

Solution code:
N=int(input())
for i in range(N):
    x,y = map(int,input().split())
    if i == 0:
        max = x+y
        min = x+y
    else:
        if max > x+y:
            max = x+y
        if min < x+y:
            min = x+y
print(abs(max-min))

Submission status: Wrong Answer

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

def gm(x, y):
    return max(map(abs, [x + y, x- y, -x + y, -x - y]))

def solve(N: int, x: "List[int]", y: "List[int]"):
    tmp = list(map(lambda x: gm(*x),  zip(x, y)))
    print(abs(min(tmp) - max(tmp)))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

max_f_0 = 0
min_f_0 = 10**10
max_f_1 = 0
min_f_1 = 10**10

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a_list=[list(map(int,input().split())) for i in range(n)]
A=[]
for i in range(n):
    A.append(a_list[i][0]**2+a_list[i][1]**2)
X=A.index(max(A))
X=int(X)
Y=A.index(min(A))
Y=int(Y)
print(abs(a_list[X][0]-a_list[Y][0])+abs(a_list[X][1]-a_list[Y][1]))

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]
maz = z[-1]
miz = 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)
xx = dic[maz]
xx.sort()
yy = dic[miz]
yy.sort()
p = [xx[-1], xx[0], yy[-1], yy[0]]
for i in p:
    for j in p:
        ans = max(ans, abs(i[0]-j[0])+abs(i[1]-j[0]))
ans = max(ans, xx[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

readline = stdin.readline

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

xy.sort()

c = set(xy[:750])
c = c | set(xy[-750:])

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

c = c | set(xy[:750])
c = c | set(xy[-750:])

c = list(c)
result = 0
for i in range(len(c)):
    for j in range(i + 1, len(c)):
        result = max(result, abs(c[i][0] - c[j][0]) + abs(c[i][1] - c[j][1]))
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [] * N
y = [] * N
for i in range(N):
    a, b = list(map(int, input().split()))
    x.append(a)
    y.append(b)
d = 0
ma = x[0] + y[0]
ima = 0
mi = x[0] + y[0]
imi = 0
for i in range(N):
    if x[i] + y[i] < mi:
        mi = x[i] + y[i]
        imi = i
    if x[i] + y[i] > ma:
        ma = x[i] + y[i]
        ima = i
d = abs(x[ima] - x[imi]) + abs(y[ima] - y[imi])
print(d)

Submission status: Wrong Answer

Solution code:
n = int(input())
maxPlus, minPlus, maxMinus, minMinus = 0, 10**9 , 0, 0**9
for _ in range(n):
    x, y = map(int, input().split())
    maxPlus = max(x + y, maxPlus)
    minPlus = min(x + y, minPlus)
    maxMinus = max(x - y, maxMinus)
    minMinus = min(x - y, minMinus)
print(max(abs(maxPlus - minPlus), abs(maxMinus - minMinus)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = map(int, input().split())
data = [[a,b]]


a1 = [a,b] #左下
a2 = [a,b] #左上
a3 = [a,b] #右上
a4 = [a,b] #右下

a5 = [a,b]
a6 = [a,b]

for i in range(n-1):
    a,b=map(int, input().split())
    data.append([a, b])
    if (a < a1[0] and b < a1[1]):
        a1 = [a,b]

    if (a < a2[0] and b > a2[1]):
        a2 = [a, b]

    if (a > a3[0] and b > a3[1]):
        a3 = [a, b]

    if (a > a4[0] and b < a4[1]):
        a4 = [a, b]

    if(a+b < a5[0]+a5[1]):
        a5 = [a,b]

    if(a+b > a6[0]+a6[1]):
        a6 = [a,b]
ans = -1
for i in data:

    a = i[0]
    b = i[1]

    ans = max(ans, abs(a1[0] - a) + abs(a1[1] - b))
    ans = max(ans, abs(a2[0] - a) + abs(a2[1] - b))
    ans = max(ans, abs(a3[0] - a) + abs(a3[1] - b))
    ans = max(ans, abs(a4[0] - a) + abs(a4[1] - b))
    ans = max(ans, abs(a5[0] - a) + abs(a5[1] - b))
    ans = max(ans, abs(a6[0] - a) + abs(a6[1] - b))

print(ans)

Submission status: Wrong Answer

Solution code:
t=int(input())
z=[]
for i in range(t):
      a,b=map(int,input().split())
      z.append([a,b])
i=0
j=i+1
o=len(z)
x1=(z[o-1])[0]
x2=(z[o-1])[1]
y1=(z[0])[0]
y2=(z[0])[1]
k=[abs(x1-y1)+abs(x2-y2)]
while(i<len(z) and j<len(z)):
      p=(z[i])[0]
      q=(z[j])[0]
      r=(z[i])[1]
      s=(z[j])[1]
      k.append(abs(q-p)+abs(s-r))
      i=i+2
      j=j+2
print(max(k))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
    x,y=[int(i) for i in input().split()]
    A.append(x)
    B.append(y)

mm = (10**9)*2
mmn = 0
mm2 = (10**9)*2
mmn2 = 0
pm = 10**9
pmn = 0
pm2 = 10**9
pmn2 = 0
mp = 10**9
mpn = 0
mp2 = 10**9
mpn2 = 0
pp = 0
ppn = 0
pp2 = 0
ppn2 = 0
for j in range (N):
    if (A[j]+B[j])>pp:

        pp = A[j]+B[j]
        ppn = j
    if (A[j]-B[j])>pm:
        pm = A[j]-B[j]
        pmn = j
    if (B[j]-A[j])>mp:
        mp = B[j]-A[j]
        mpn = j
    if (A[j]+B[j])<mm:
        mm = A[j]+B[j]
        mmn = j
ans1 = abs(A[ppn] - A[mmn]) + abs(B[ppn] - B[mmn])
ans2 = abs(A[pmn] - A[mpn]) + abs(B[mpn] - B[pmn])
ans = max(ans1,ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
    x = list(map(int, input().split()))
    s.append(x)
t = sorted(s)
u = sorted(s, key=lambda x: x[1])
res = 0

for X in [t[0], u[0]]:
    for Y in [t[-1], u[-1]]:
        tmp = abs(X[0] - Y[0]) + abs(X[1] - Y[1])
        res = max(res, tmp)
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl, yl = [], []
for _ in range(n):
    x, y = map(int, input().split())
    xl.append(x)
    yl.append(y)
xl_ = xl.copy()
yl_ = yl.copy()
xl_.sort()
yl_.sort()

if n%2:
    xm, ym = xl_[n//2], yl_[n//2]
else:
    xm, ym = (xl_[n//2-1]+xl_[n//2])/2, (yl_[n//2-1]+yl_[n//2])/2

xm, ym = xm-1e-6, ym-1e-6
ans1, ans2, ans3, ans4 = 0, 0, 0, 0
for i in range(n):
    if xl[i] > xm:
        if yl[i] > ym:
            ans1 = max(ans1, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans4 = max(ans4, abs(xl[i]-xm)+abs(yl[i]-ym))
    else:
        if yl[i] > ym:
            ans2 = max(ans2, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans3 = max(ans3, abs(xl[i]-xm)+abs(yl[i]-ym))
ans = int(max(abs(ans1+ans3), abs(ans2+ans4)))

xm, ym = xm+1e-6, ym+1e-6
ans1, ans2, ans3, ans4 = 0, 0, 0, 0
for i in range(n):
    if xl[i] > xm:
        if yl[i] > ym:
            ans1 = max(ans1, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans4 = max(ans4, abs(xl[i]-xm)+abs(yl[i]-ym))
    else:
        if yl[i] > ym:
            ans2 = max(ans2, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans3 = max(ans3, abs(xl[i]-xm)+abs(yl[i]-ym)) 
ans = max(ans, int(max(abs(ans1+ans3), abs(ans2+ans4))))

xm, ym = xm-1e-6, ym+1e-6
ans1, ans2, ans3, ans4 = 0, 0, 0, 0
for i in range(n):
    if xl[i] > xm:
        if yl[i] > ym:
            ans1 = max(ans1, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans4 = max(ans4, abs(xl[i]-xm)+abs(yl[i]-ym))
    else:
        if yl[i] > ym:
            ans2 = max(ans2, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans3 = max(ans3, abs(xl[i]-xm)+abs(yl[i]-ym)) 
ans = max(ans, int(max(abs(ans1+ans3), abs(ans2+ans4))))

xm, ym = xm+1e-6, ym-1e-6
ans1, ans2, ans3, ans4 = 0, 0, 0, 0
for i in range(n):
    if xl[i] > xm:
        if yl[i] > ym:
            ans1 = max(ans1, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans4 = max(ans4, abs(xl[i]-xm)+abs(yl[i]-ym))
    else:
        if yl[i] > ym:
            ans2 = max(ans2, abs(xl[i]-xm)+abs(yl[i]-ym))
        else:
            ans3 = max(ans3, abs(xl[i]-xm)+abs(yl[i]-ym)) 
ans = max(ans, int(max(abs(ans1+ans3), abs(ans2+ans4))))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = sorted([list(map(int, input().split(" "))) for i in range(n)])
base = a[0][0] + a[0][1]
maxi = 0
for i in range(n):
  if a[0][0] + a[0][1] > base:
    continue
  else:
    for j in range(i + 1, n):
      maxi = max(maxi, (a[j][0] - a[i][0]) + (a[j][1] - a[i][1]))
print(maxi)

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], x[1]))
L2=sorted(L, key=lambda x:(x[1], x[0]))
print(L1,L2)
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:
beforex=0
beforey=0
sum=0
for i in range(int(input())):
  xy=list(map(int,input().split()))
  if i == 0:
    beforex=xy[0]
    beforey=xy[1]
  sum=max(sum,abs(beforex-xy[0])+abs(beforey-xy[1]))
  beforex=xy[0]
  beforey=xy[1]

print(sum)

Submission status: Wrong Answer

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

x.sort(key=lambda y: y[0])


def dist(x_1, y_1, x_2, y_2):
    return abs(x_1 - x_2) + abs(y_1 - y_2)


ans = 0

for i in range(N):
    tmp = dist(*x[i], *x[0])
    if tmp > ans:
        ans = tmp
    tmp = dist(*x[i], *x[N-1])
    if tmp > ans:
        ans = tmp


x.sort(key=lambda y: y[1])

for i in range(N):
    tmp = dist(*x[i], *x[0])
    if tmp > ans:
        ans = tmp
    tmp = dist(*x[i], *x[N-1])
    if tmp > ans:
        ans = tmp


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x, y, xy = [], [], []
for i in range(n):
	temp_x, temp_y = map(int, input().split())
	x.append(temp_x)
	y.append(temp_y)
	xy.append(temp_x * temp_y)
max_index, min_index = xy.index(max(xy)), xy.index(min(xy))
print(abs(x[max_index] - x[min_index]) + abs(y[max_index] - y[min_index]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]


N = int(input())
md = []
for i in range(N):
    x, y = li()
    md.append(x + y)

maxv = max(md)
minv = min(md)
ans = abs(maxv - minv)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = list(list(map(int,input().split())) for _ in range(n))
l = []
for i in range(n):
    l.append(xy[i][0]+xy[i][1])
d = abs(xy[l.index(max(l))][0]-xy[l.index(min(l))][0])+abs(xy[l.index(max(l))][1]-xy[l.index(min(l))][1])
print(d)

Submission status: Wrong Answer

Solution code:
from sys import stdin

readline = stdin.readline

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

xy.sort()

c = set(xy[:500])
c = c | set(xy[-500:])

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

c = c | set(xy[:500])
c = c | set(xy[-500:])

c = list(c)
result = 0
for i in range(len(c)):
    for j in range(i + 1, len(c)):
        result = max(result, abs(c[i][0] - c[j][0]) + abs(c[i][1] - c[j][1]))
print(result)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())
p = []
for _ in range(N):
    x, y = map(int, input().split())
    p.append((x, y))
px = sorted(p, key=lambda i: i[0])
py = sorted(p, key=lambda i: i[1])
res = 0
for p1, p2 in combinations([px[0], px[-1], py[0], py[-1]], 2):
    res = max(res, abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]))
print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=0
t1,t2=map(int,input().split())
for i in range(n-1):
    x,y=map(int,input().split())
    xn=(x-t1)
    yn=(y-t2)
    
    if xn<0:
        xn=xn*(-1)
    
    if yn<0:
        yn=yn*(-1)
    
    l=xn+yn
    
    t1=x
    t2=y
    
    if l>m:
        m=l
    
print(m)

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)]
maxx = 0

result = [0]
for i in range(n):
  if maxx < i:
    for j in range(n):
      result.append(abs(x[i] - x[j]) + abs(y[i] - y[j]))
      maxx = x[i]
print(max(result))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]


N = int(input())
md = []
for i in range(N):
    x, y = li()
    md.append(x + y)

maxv = max(md)
minv = min(md)

print(maxv - minv)

Submission status: Wrong Answer

Solution code:
N = int(input())

max_f_0 = 0
min_f_0 = 10**9
max_f_1 = 0
min_f_1 = 10**9

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

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [] * N
y = [] * N
for i in range(N):
    a, b = list(map(int, input().split()))
    x.append(a)
    y.append(b)
d = 0
ma = x[0] + y[0]
ima = 0
mi = x[0] + y[0]
imi = 0
for i in range(N):
    if x[i] + y[i] < mi:
        mi = x[i] + y[i]
        imi = i
    if x[i] + y[i] > ma:
        ma = x[i] + y[i]
        ima = i
print (ima, imi)
d = abs(x[ima] - x[imi]) + abs(y[ima] - y[imi])
print(d)

Submission status: Wrong Answer

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

ans = max(ans, abs(ur[0]-dl[0])+abs(ur[1]-dl[1]))
ans = max(ans, abs(ul[0]-dr[0])+abs(ul[1]-dr[0]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

x_list = []
y_list = []

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

max_x = max(x_list)
min_x = min(x_list)
max_y = max(y_list)
min_y = min(y_list)

point_list = []
for i in range(N):
    if x_list[i] == max_x or x_list[i] == min_x or y_list[i] == max_y or y_list[i] == min_y:
        point_list.append([x_list[i], y_list[i]])

ans = 0
for i in range(len(point_list)):
    point_a = point_list[i]
    for j in range(i+1, len(point_list)):
        point_b = point_list[j]
        ans = max(ans, abs(point_a[0] - point_b[0]) + abs(point_a[1] - point_b[1]))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

def distant(d1,d2):
  return abs(d1[0]-d2[0])+abs(d1[1]-d2[1])

d0=tuple(map(int,input().split()))
d1=tuple(map(int,input().split()))
dist=distant(d0,d1)

for i in range(n-2):
  d=list(map(int,input().split()))
  tmp=distant(d0,d)
  if tmp>dist:
    d0=d
    dist=tmp
  tmp=distant(d1,d)
  if tmp>dist:
    d1=d
    dist=tmp
print(dist)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [tuple(map(int, input().split())) for i in range(N)]
d=set()
for i, j in zip(list(range(N)),list(range(1,N))):
    d.add(abs(l[i][0]-l[j][0]) + abs(l[i][1]-l[j][1]))
print(max(d))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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