有个结论就是把坐标((x,y))变形成(((x+y)/2,(x-y)/2)),切比雪夫距离就变成了曼哈顿距离。
所以变换一下坐标直接统计答案即可。
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il int gi(){
int x=0,f=1;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-')f=-1;
ch=getchar();
}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return x*f;
}
struct yyb{ll x,y;}s[100010];
il bool operator <(const yyb&a,const yyb&b){return a.x<b.x;}
ll Y[100010],sY[100010],sX[100010];
int main(){
#ifndef ONLINE_JUDGE
freopen("3964.in","r",stdin);
freopen("3964.out","w",stdout);
#endif
int n=gi();
for(int i=1;i<=n;++i){
int x=gi(),y=gi();
s[i].x=x+y,s[i].y=x-y;
Y[i]=s[i].y;
}
std::sort(s+1,s+n+1);
std::sort(Y+1,Y+n+1);
for(int i=1;i<=n;++i)sY[i]=sY[i-1]+Y[i];
for(int i=1;i<=n;++i)sX[i]=sX[i-1]+s[i].x;
ll ans=1e18;
for(int i=1;i<=n;++i){
int p=std::lower_bound(Y+1,Y+n+1,s[i].y)-Y;
ans=std::min(ans,-sX[i]*2+(i+i-n)*s[i].x+sX[n]-sY[p]*2+(p+p-n)*s[i].y+sY[n]);
}
printf("%lld
",ans/2);
return 0;
}