# bzoj3170【TJOI2013】松鼠聚会

## 3170: [Tjoi 2013]松鼠聚会

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 965  Solved: 475
[Submit][Status][Discuss]

-10^9<=x,y<=10^9

6
-4 -1
-1 -2
2 -4
0 2
0 3
5 -2

## Sample Output

20

A(x1,y1)与B(x2,y2)的切比雪夫距离等于A’(x1+y1,x1-y1)和B’(x2+y2,x2-y2)的曼哈顿距离。证明只需将两边同时平方，再稍加化简即可。

`#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=j;i>=n;i--)#define ll long long#define maxn 100005#define inf 1000000000000000000llusing namespace std;int n,pos,x[maxn],y[maxn];ll ans,tmp,sumx[maxn],sumy[maxn];struct data{ll x,y;}a[maxn];inline int read(){int x=0,f=1;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}int main(){n=read();F(i,1,n){int xx=read(),yy=read();x[i]=a[i].x=xx+yy;y[i]=a[i].y=xx-yy;}sort(x+1,x+n+1);sort(y+1,y+n+1);F(i,1,n) sumx[i]=sumx[i-1]+x[i],sumy[i]=sumy[i-1]+y[i];ans=inf;F(i,1,n){pos=lower_bound(x+1,x+n+1,a[i].x)-x;tmp=sumx[n]-sumx[pos]-a[i].x*(n-pos)+a[i].x*pos-sumx[pos];pos=lower_bound(y+1,y+n+1,a[i].y)-y;tmp+=sumy[n]-sumy[pos]-a[i].y*(n-pos)+a[i].y*pos-sumy[pos];ans=min(ans,tmp);}printf("%lld\n",ans/2);return 0;}`

0 0