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:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
xy = [readInts() for _ in range(n)]
max_xplusy = -1
min_xplusy = INF
for i in range(n):
    x,y = xy[i]
    max_xplusy = max(max_xplusy, x+y)
    min_xplusy = min(min_xplusy, x+y)
a = max_xplusy - min_xplusy
max_xminusy = -1
min_xminusy = INF
for i in range(n):
    x,y = xy[i]
    max_xminusy = max(max_xminusy, x-y)
    min_xminusy = min(min_xminusy, x-y)
b = max_xminusy - min_xminusy
print(max(a,b))

Submission status: Wrong Answer

Solution code:
n = int(input())
str_list = [list(input().split()) for _ in range(n)]
count = 0
for n in str_list:
    if count == 0:
        l = abs(int(n[0]))+ abs(int(n[1]))
        h = abs(int(n[0]))+ abs(int(n[1]))
        low = n
        high = n
        count += 1
        continue
    if (int(n[0]))+ abs(int(n[1])) <  l:
        l = abs(int(n[0]))+ abs(int(n[1]))
        low = n
        continue
    if (int(n[0]))+ abs(int(n[1])) > h:
        h = abs(int(n[0]))+ abs(int(n[1]))
        high = n
        continue
print(abs(int(low[0])-int(high[0])) + abs(int(low[1])-int(high[1])))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []

for i in range(n):
    x , y = map(int,input().split());
    a.append(x + y)
    b.append(abs(x - y))

aa = max(a)-min(a)
bb = max(b)-min(b)

if aa >= bb:
    print(aa)
else:
    print(bb)

Submission status: Wrong Answer

Solution code:
Row=int(input())
X=[]
Y=[]
for i in range(Row):
    n,a=input().split()
    X.append(int(n))
    Y.append(int(a))
A=[]
B=[]
for i in range(len(X)):
    A.append(X[i]-Y[i])
    B.append(X[i]+Y[i])
maxmax1=0
maxmax2=0
minmin1=10**10
minmin2=10**10
for i in range(len(A)):
    maxmax1=max(maxmax1,A[i])
    minmin1=min(minmin1,A[i])
for i in range(len(B)):
    maxmax2=max(maxmax2,B[i])
    minmin2=min(minmin2,B[i])
print(max((maxmax1-minmin1),(maxmax2-minmin2)))

Submission status: Wrong Answer

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

minD = 2 * 10**9
min = 0
maxD = 0
max = 0

for i in range(N):
    if (minD > (hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1])):
        minD = hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1]
        min = i
    if (maxD < hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1]):
        maxD = hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1]
        max = i

print(abs(hw[max][0] - hw[min][0]) + abs(hw[max][1] - hw[min][1]))

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()))
for i in x:
    i.append(abs(x[0][0]-i[0]) + abs(x[0][1]-i[1]))
x.sort(key = lambda s:s[2])
ans = 0
for j in range(n):
        ans = max(ans, abs(x[-1][0] - x[j][0]) + abs(x[-1][1] - x[j][1]))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
hidarisita=2*10**9
migiue=0
migisita=2*10**9
hidariue=0
x=[]
for i in range(0,n):
    x.append(list(map(int, input().split())))
    
for i in range(0,n):#左下
    minlocal=x[i][0]+x[i][1]
    if minlocal<hidarisita:
        hidarisita=minlocal
for i in range(0,n):#右上
    maxlocal=x[i][0]+x[i][1]
    if maxlocal>migiue:
        migiue=maxlocal
for i in range(0,n):#左上
    local=-x[i][0]+10*9+x[i][1]
    if maxlocal>hidariue:
        hidariue=local
for i in range(0,n):#右下
    minlocal=-x[i][0]+10**9+x[i][1]
    if minlocal<migisita:
        migsita=minlocal

print(max(migiue-hidarisita,hidariue-migisita))

Submission status: Wrong Answer

Solution code:
# # input here
# _INPUT = """\

# """

import numpy as np
from scipy.spatial import distance
def main():
    n = int(input())
    lis = []
    for i in range(n):
        x,y = map(int, input().split())
        lis.append([x,y])
    M = np.array(lis)
    try:
        dist_M = distance.cdist(M, M, metric='cityblock')
        print(str(np.max(dist_M)).split('.')[0])
    except:
        print(0)
if __name__ == '__main__':
    # import io
    # import sys
    # sys.stdin = io.StringIO(_INPUT)
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

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

    def calc_dist(pi):
        ret = -1
        reti = -1
        px, py = P[pi]
        for i, (x, y) in enumerate(P):
            d = abs(px - x) + abs(py - y)
            if d > ret:
                ret = d
                reti = i
        return ret, reti

    prev = -2
    ans = -1

    used = {0}
    from random import randrange

    i = 0
    for _ in range(100):
        ans, i = calc_dist(i)
        # if ans == prev:
        #     print(ans)
        #     return
        if prev < ans:
            prev = ans

        if len(used) == N:
            break

        while i in used:
            i = randrange(0, N)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math as mt
import sys
import bisect
input=sys.stdin.readline
#t=int(input())
t=1
def maxAbsValExpr( x, y):
    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)
    return res



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

    print( maxAbsValExpr(l,l1)-1)

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


xm, ym = xl_[n//2-1], yl_[n//2-1]
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 = xl_[n//2], yl_[n//2]
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 = (xl_[n//2-1]+xl_[n//2])/2, (yl_[n//2-1]+yl_[n//2])/2
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)))

print(max(ans, ans_, ans__))

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())

    xs, ys = [], []
    for _ in range(N):
        x, y = map(int, input().split())
        xs.append(x)
        ys.append(y)
    
    T, B = max(ys), min(ys)
    L, R = min(xs), max(xs)

    # print(T, B, L, R)

    if T == B:
        return abs(R - L)

    if L == R:
        return abs(T - B)

    # T, B
    top_l, top_r = 10**10, -1
    bot_l, bot_r = 10**10, -1
    for i in range(N):
        if ys[i] == T:
            top_l = min(top_l, xs[i])
            top_r = max(top_r, xs[i])
        if ys[i] == B:
            bot_l = min(bot_l, xs[i])
            bot_r = max(bot_r, xs[i])

    # print(top_l, top_r)
    # print(bot_l, bot_r)

    # L, R
    left_t, left_b = -1, 10**10
    right_t, right_b = -1, 10**10
    for i in range(N):
        if xs[i] == L:
            left_t = max(left_t, ys[i])
            left_b = min(left_b, ys[i])
        if xs[i] == R:
            right_t = max(right_t, ys[i])
            right_b = min(right_b, ys[i])

    # print(left_t, left_b)
    # print(right_t, right_b)

    ans = -1
    for i in range(N):
        if ys[i] == T:
            d1 = abs(T - B) + abs(xs[i] - bot_l)
            d2 = abs(T - B) + abs(xs[i] - bot_r)
            ans = max(ans, max(d1, d2))
        if ys[i] == B:
            d1 = abs(T - B) + abs(xs[i] - top_l)
            d2 = abs(T - B) + abs(xs[i] - top_r)
            ans = max(ans, max(d1, d2))
        if xs[i] == L:
            d1 = abs(R - L) + abs(ys[i] - right_t)
            d2 = abs(R - L) + abs(ys[i] - right_b)
            ans = max(ans, max(d1, d2))
        if xs[i] == R:
            d1 = abs(R - L) + abs(ys[i] - left_t)
            d2 = abs(R - L) + abs(ys[i] - left_b)
            ans = max(ans, max(d1, d2))
    return ans


print(solve())

Submission status: Wrong Answer

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

def main(n,xy):
    gx=0
    gy=0
    for x,y in xy:
        gx+=x
        gy+=y
    gx=gx/n
    gy=gy/n
    xy1=0.0
    xy2=0.0
    xy3=0.0
    xy4=0.0
    for x,y in xy:
        x-=gx
        y-=gy
        if x >=0 and y >= 0:
            xy1=max(xy1,x+y)
        elif x <0 and y >= 0:
            xy2=max(xy2,-x+y)
        elif x < 0 and y < 0:
            xy3=max(xy3,-x-y)
        else:
            xy4=max(xy4,x-y)
    xymax=max(xy1+xy3,xy2+xy4)
    xymax=int(xymax+0.5)        


    return xymax

if __name__=='__main__':
    n,xy=readinput()
    ans=main(n,xy)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xpy_max = - (10 ** 9 + 3) 
xpy_min = 10 ** 9 + 3
xmy_max = - (10 ** 9 + 3)
xmy_min = 10 ** 9 + 3
for i in range(N):
    x, y = map(int, input().split())
    if x + y <= xpy_min:
        xpy_min = x + y
        a = (x, y)
    if x + y >= xpy_max:
        xpy_max = x + y
        b = (x, y)
    if x - y >= xmy_max:
        xmy_max = x - y
        c = (x, y)
    if x - y <= xmy_min:
        xmy_min = x - y
        d = (x, y)
ans = max(b[0] - a[0] + b[1] - a[1], c[0] - d[0] + c[1] - d[1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
a = 0
b = 0
l = [0]*n

for i in range(n):
    a += ab[i][0]
    b += ab[i][1]

a = a/n
b = b/n

for j in range(n):
    l[j] = abs(ab[j][0]-a) + abs(ab[j][1]-b)

c = l.index(max(l))
l[c] = 0
d = l.index(max(l))

e = abs(ab[c][0]-ab[d][0]) + abs(ab[c][1]-ab[d][1])
print(e)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

md = 0
for i in range(n-1):
    for j in range(i+1,n):
        d1 = abs(cd[i][0] - cd[j][0])
        d2 = abs(cd[i][1] - cd[j][1])
        print(d1, d2)
        md = max(md, d1, d2)

print(md)

Submission status: Wrong Answer

Solution code:
import sys
import random

random.seed(1)

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

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)

first_jibuns = set([random.randint(0, n-1) for i in range(20)])
#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):
    max_dist = -1
    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
        else:
            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())

ans = 0
tmp_M0 = 0
tmp_m0 = float("inf")
tmp_M1 = 0
tmp_m1 = float("inf")
for i in range(N):
    x,y =map(int, input().split())
    if x-y > tmp_M0:
        tmp_M0 = x-y
    if x-y < tmp_m0:
        tmp_m0 = x-y
    if x+y > tmp_M1:
        tmp_M1 = x+y
    if x+y < tmp_m1:
        tmp_m1 = x+y
    
    if max(tmp_M0-tmp_m0, tmp_M1-tmp_m1) > ans:
        ans = max(tmp_M0-tmp_m0, tmp_M1-tmp_m1)
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
xy=[tuple(map(int,input().split())) for _ in range(N)]
t=[]
for x,y in xy:
    t.append((x*y,x,y))
t=sorted(t)
tt=[]
tt.append(t[0])
tt.append(t[-1])
t=sorted(t,key=lambda x:x[1])
tt.append(t[0])
tt.append(t[-1])
t=sorted(t,key=lambda x:x[2])
tt.append(t[0])
tt.append(t[-1])
n=len(tt)
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans=max(ans,abs(tt[i][1]-tt[j][1])+abs(tt[i][2]-tt[j][2]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

m1 = A[0]
m2 = A[1]
mx = abs(A[0][0] - A[1][0]) + abs(A[0][1] - A[1][1])

M = [[m1, m2]]


def calc_length(m1, m2):
    return abs(m1[0] - m2[0]) + abs(m1[1] - m2[1])


for i in range(2, N):
    for j in range(len(M)):
        m1, m2 = M[j]
        l1 = calc_length(m1, A[i])
        l2 = calc_length(m2, A[i])
        if l1 > mx and l2 > mx:
            if l1 == l2:
                m2 = A[i]
                mx = l1
                M.append([m1, A[i]])
            if l1 > l2:
                m2 = A[i]
                mx = l1
            else:
                m1 = A[i]
                mx = l2
        elif l1 > mx:
            m2 = A[i]
            mx = l1
        elif l2 > mx:
            m1 = A[i]
            mx = l2
        M[j] = m1, m2

print(mx)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

#             print(dis_from_edge0, dis_from_edge1)
            # 更新なし
            if max(dis_from_edge0, dis_from_edge1) <= dis:
#                 print('#1', edge0, edge1, dis)
                continue
            # どちらも更新
            if min(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]
#                 print('#2', edge0, edge1, dis)
                continue
            if dis_from_edge0 > dis:
                dis = dis_from_edge0
                edge1 = [x, y]
#                 print('#3', edge0, edge1, dis)
                continue
            if dis_from_edge1 > dis:
                dis = dis_from_edge1
                edge0 = [x, y]
                continue
print(dis)

    #     x_max = max(x, x_max)
    #     x_min = min(x, x_min)
    #     y_max = max(y, y_max)
    #     y_min = min(y, y_min)

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[list(map(int,input().split())) for i in range(N)]
a,b=0,0
fa,fb,sa,sb=0,0,0,0
memf,memc=0,0
for i,j in l:
   a+=i
   b+=j
a/=N;b/=N
for i,j in l:
   if abs(i-a)+abs(j-b)>memc:
      if abs(i-a)+abs(j-b)>memf:
         sa,sb=fa,fb
         fa,fb=i,j
         memc=memf
         memf=abs(i-a)+abs(j-b)
      else:
         sa,sb=i,j
         memc=abs(i-a)+abs(j-b)
print(abs(fa-sa)+abs(fb-sb))

Submission status: Wrong Answer

Solution code:
N = int(input())
x, y = map(int,input().split())
min_x = x
max_x = x
min_y = y
max_y = y
L = x ** 2 + y ** 2
min_L = L
max_L = L

cont = 10**9
min_x2 = x
max_x2 = x
min_y2 = y
max_y2 = y
L2 = x ** 2 + (cont - y) ** 2
min_L2 = L2
max_L2 = L2

for i in range(N-1):
  x, y = map(int, input().split())
  L = x ** 2 + y ** 2
  if min_L > L:
    min_x = x
    min_y = y
    min_L = L
  elif max_L < L:
    max_x = x
    max_y = y
    max_L = L
    
  L2 = x ** 2 + (cont - y) ** 2
  if min_L2 > L2:
    min_x2 = x
    min_y2 = y
    min_L2 = L2
  elif max_L2 < L2:
    max_x2 = x
    max_y2 = y
    max_L2 = L2
ans = max_x - min_x + max_y - min_y
ans2 = max_x2 - min_x2 + min_y2 - max_y2
print(max(ans,ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
for i in range(n):
  x.append(list(map(int, input().split())))
a=2*(10**9)
b=0

for j in range(n):
  if sum(x[j])<a:
    a=sum(x[j])
    c=j
  if sum(x[j])>b:
    b=sum(x[j])
    d=j
if c==d:
  print(0)
else:
  print(x[d][0]-x[c][0]+x[d][1]-x[c][1])

Submission status: Wrong Answer

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

minD = 2 * 10**9
min = 0
maxD = 0
max = 0

for i in range(N):
    if (minD > (hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1])):
        minD = hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1]
        min = i
    elif (maxD < hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1]):
        maxD = hw[i][0]*hw[i][0] + hw[i][1]*hw[i][1]
        max = i

print(abs(hw[max][0] - hw[min][0]) + abs(hw[max][1] - hw[min][1]))

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
xy=sorted(xy, key=lambda x:x[0])
m=10**9+7
mi=-1
Mi=-1
M=0
res=[]
ans=0
for i in range(n-1,0,-1):
    x,y=xy[i]
    if y<=m:
        mi=i
        m=y
    if y>=M:
        Mi=i
        M=y
    res.append([mi,Mi])
for i in range(n-1):
    x,y=xy[i]
    rm,rM=res[n-2-i]
    xm,ym=xy[rm]
    xM,yM=xy[rM]
    c=max((abs(x-xm)+abs(y-ym)),(abs(x-xM)+abs(y-yM)))
    ans=max(c,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
max_t = -float('inf')
min_t = float('inf')
max_p_x = []
min_p_x = []
for _ in range(n):
  x, y = map(int, input().split())
  c = x + y
  if c > max_t:
    max_t = c
    max_p_x = [x]
  elif c == max_t:
    max_p_x.append(x)
  if c < min_t:
    min_t = c
    min_p_x = [x]
  elif c == min_t:
    min_p_x.append(x)
max_d = max_t - min_t
max_l = len(max_p_x)
min_l = len(min_p_x)
if max_l > 1:
  a, b = max(max_p_x), min(max_p_x)
  dis = (a - b) * 2
  max_d = max(max_d, dis)
if min_l > 1:
  a, b = max(min_p_x), min(min_p_x)
  dis = (a - b) * 2
  max_d = max(max_d, dis)
print(max_d)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list()
for i in range(n):
  x,y=map(int,input().split())
  l.append((x,y))

minx = sorted(l, key=lambda x: x[0])
maxx = sorted(l, key=lambda x: x[0], reverse=True)
miny = sorted(l, key=lambda x: x[1])
maxy = sorted(l, key=lambda x: x[1], reverse=True)

ans=0
c=0
for imaxx in maxx:
  for iminx in minx:
    dist=(abs(imaxx[0]-iminx[0]) + abs(imaxx[1] - iminx[1]))
    ans=max(ans, dist)
    c+=1
    if c==20:
      c=0
      break

  else:
    continue
  break

for imaxx in maxx:
  for iminy in miny:
    dist=(abs(imaxx[0]-iminy[0]) + abs(imaxx[1] - iminy[1]))
    ans=max(ans, dist)
    c+=1
    if c==20:
      c=0
      break

  else:
    continue
  break

for imaxy in maxy:
  for iminy in miny:
    dist=(abs(imaxy[0]-iminy[0]) + abs(imaxy[1] - iminy[1]))
    ans=max(ans, dist)
    c+=1
    if c==20:
      c=0
      break

  else:
    continue
  break


for imaxy in maxy:
  for iminx in minx:
    dist=(abs(imaxy[0]-iminx[0]) + abs(imaxy[1] - iminx[1]))
    ans=max(ans, dist)
    c+=1
    if c==20:
      c=0
      break

  else:
    continue
  break

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  num_1 = [[0, 0] for j in range(3)]
  num_2 = [[0, 0] for j in range(3)]
  num_3 = [[0, 0] for j in range(3)]
  num_4 = [[0, 0] for j in range(3)]
  
  flg1 = 0
  flg2 = 0
  flg3 = 0
  flg4 = 0
  
  best = 0
  
  for _ in range(N):
    x, y = map(int, input().split())
        
    if flg1 == 1:
      for a_x, a_y in num_1:
        dis = abs(x - a_x) + abs(y - a_y)
        if dis > best:
          best = dis
    if flg2 == 1:
      for a_x, a_y in num_2:
        dis = abs(x - a_x) + abs(y - a_y)
        if dis > best:
          best = dis
    if flg3 == 1:
      for a_x, a_y in num_3:
        dis = abs(x - a_x) + abs(y - a_y)
        if dis > best:
          best = dis
    if flg4 == 1:
      for a_x, a_y in num_4:
        dis = abs(x - a_x) + abs(y - a_y)
        if dis > best:
          best = dis
          
    if x>=0 and y>=0:
      flg1 = 1
      if num_1[0][0] < x:
        num_1[0] = [x,y]
      if num_1[1][1] < y:
        num_1[1] = [x,y]
      if num_1[2][0] + num_1[2][1]< x+y:
        num_1[2] = [x,y]
        
    if x<=0 and y>=0:
      flg2 = 1
      if num_2[0][0] > x:
        num_2[0] = [x,y]
      if num_2[1][1] < y:
        num_2[1] = [x,y]
      if -num_2[2][0] + num_2[2][1]< -x + y:
        num_2[2] = [x,y]
        
    if x<=0 and y<=0:
      flg3 = 1
      if num_3[0][0] > x:
        num_3[0] = [x,y]
      if num_3[1][1] > y:
        num_3[1] = [x,y]
      if -num_3[2][0] - num_3[2][1]< -x -y:
        num_3[2] = [x,y]
    
    if x>=0 and y<=0:
      flg4 = 1
      if num_4[0][0] < x:
        num_4[0] = [x,y]
      if num_4[1][1] > y:
        num_4[1] = [x,y]
      if num_4[2][0] - num_4[2][1]< x -y:
        num_4[2] = [x,y]
        
  print(best)
main()

Submission status: Wrong Answer

Solution code:
import sys
import random

random.seed(1)

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

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)

first_jibuns = set([random.randint(0, n-1) for i in range(10)])
#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):
    max_dist = -1
    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
        else:
            jibun = next_jibun 
            fmax_dist = max_dist

    final_out = max(final_out, out)
    
    
print(final_out)

Submission status: Wrong Answer

Solution code:
import os
import heapq

import sys
import bisect
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
from functools import reduce


def convex_hull_graham(coordinates):
    def change(a, b, c):
        return ((b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1])) < 0

    def left(h, r):
        while len(h) > 1 and change(h[-2], h[-1], r):
            h.pop()
        h.append(r)
        return h

    coordinates.sort()
    lower = reduce(left, coordinates, [])
    upper = reduce(left, reversed(coordinates), [])


    return lower.extend(upper[1:len(upper) - 1]) or lower
def d(one,t):
    return abs(one[0]-t[0])+abs(one[1]-t[1])
def find_max_dist_graham_c1(L):
    L = convex_hull_graham(L)  # Get ordered list of convex hull points
    max_dist = d(L[0], L[1])
    for i in range(0, len(L)-1):
        loop_max_dist = 0
        for j in range(i+1, len(L)):
            curr_dist = d(L[i], L[j])
            if curr_dist < loop_max_dist:
                break
            loop_max_dist = curr_dist
            max_dist = max(loop_max_dist, max_dist)

    return max_dist

def main():
    n=int(input())
    arr = []
    for i in range(n):
        x, y = map(int, input().split())
        arr.append([x, y])
    print(find_max_dist_graham_c1(arr))
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x_1 = [0,0]
x_2 = [0,0]
x_3 = [0,0]
x_4 = [0,0]

for i in range(n):
    c,d = (map(int,input().split()))
    a = abs(c)
    b = abs(d)
    if i == 0:
        x_1 = [c,d]
    elif i == 1:
        x_2 = [c,d]
    elif i == 2:
        x_3 = [c,d]
    elif i == 3:
        x_4 = [c,d]
    else:
        if c >= 0 and d >= 0:
            if x_1[0] + x_1[1] < a+b:
                x_1[0] = c
                x_1[1] = d
        elif c >= 0 and d < 0:
            if x_3[0] + abs(x_3[1]) < a+b:
                x_3[0] = c
                x_3[1] = d
        elif c < 0 and d >= 0:
            if abs(x_2[0]) + x_2[1] < a+b:
                x_2[0] = c
                x_2[1] = d
        elif c < 0 and d < 0:
            if abs(x_4[0]) + abs(x_4[1]) < a+b:
                x_4[0] = c
                x_4[1] = d
e_1 = 0
e_2 = 0
e_3 = 0
e_4 = 0
e_5 = 0
e_6 = 0

if n == 2:
    e_1 = abs(x_1[0] - x_2[0]) + abs(x_1[1] - x_2[1])
elif n == 3:
    e_1 = abs(x_1[0] - x_2[0]) + abs(x_1[1] - x_2[1])
    e_2 = abs(x_1[0] - x_3[0]) + abs(x_1[1] - x_3[1])
    e_4 = abs(x_2[0] - x_3[0]) + abs(x_2[1] - x_3[1])
else:    
    e_1 = abs(x_1[0] - x_2[0]) + abs(x_1[1] - x_2[1])
    e_2 = abs(x_1[0] - x_3[0]) + abs(x_1[1] - x_3[1])
    e_3 = abs(x_1[0] - x_4[0]) + abs(x_1[1] - x_4[1])
    e_4 = abs(x_2[0] - x_3[0]) + abs(x_2[1] - x_3[1])
    e_5 = abs(x_2[0] - x_4[0]) + abs(x_2[1] - x_4[1])
    e_6 = abs(x_3[0] - x_4[0]) + abs(x_3[1] - x_4[1])

print(max(e_1,e_2,e_3,e_4,e_5,e_6))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]
#CW = [list(map(int, list(input()))) for _ in range(H)]


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

for i in range(N):
  xy2[i] = xy[i][0] + xy[i][1]

ma = xy2.index(max(xy2))
mi = xy2.index(min(xy2))

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

print(ans)

Submission status: Wrong Answer

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

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

ans = abs(points[0][0] - points[-1][0]) + abs(points[0][1] - points[-1][1])

print(ans)