嘟嘟嘟
看完题后突然想起jf巨佬的话:“看到曼哈顿距离就想转切比雪夫距离。”
于是我就转换了一下。
然后问题变成了求
[max_{i, j in n} { max { |x_i - x_j|, |y_i - y_j| } }
]
令差最大,只要分别找出(x, y)的最小值和最大值即可。
(O(n))扫一遍啦。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 5e4 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = (ans << 1) + (ans << 3) + ch - '0'; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n;
struct Node
{
int x, y;
}t[maxn];
int main()
{
n = read();
for(int i = 1; i <= n; ++i)
{
int x = read(), y = read();
t[i] = (Node){x + y, x - y};
}
int Max = 1, May = 1, Mix = 1, Miy = 1;
for(int i = 2; i <= n; ++i)
{
if(t[i].x < t[Mix].x) Mix = i;
if(t[i].x > t[Max].x) Max = i;
if(t[i].y < t[Miy].y) Miy = i;
if(t[i].y > t[May].y) May = i;
}
write(max(t[Max].x - t[Mix].x, t[May].y - t[Miy].y)), enter;
return 0;
}