# BZOJ3170[TJOI2013]松鼠聚会

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

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 364  Solved: 169
[Submit][Status]

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

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

20

## Source

y轴也同理

`/**************************************************************    Problem: 3170    User: SKYDEC    Language: C++    Result: Accepted    Time:728 ms    Memory:7840 kb****************************************************************/ #include<stdio.h>#include<algorithm>#define BUG printf("yeah!")#define MAXN 100005#define Rep(i,j,k) for(long i=j;i<=k;i++)#define DRep(i,j,k) for(long i=j;i>=k;i--)using namespace std;double ans=0;long long n;struct decar{double x,y;long long num;}a[MAXN];long long posx[MAXN],posy[MAXN];double qy[MAXN],dy[MAXN],qx[MAXN],dx[MAXN];bool cmpx(decar a,decar b){return a.x<b.x;}bool cmpy(decar a,decar b){return a.y<b.y;}long long abs(long long x){if(x<0)return -x;else return x;}int main(){    //freopen("meeting.in","r",stdin);freopen("meeting.out","w",stdout);    scanf("%lld",&n);Rep(i,1,n){scanf("%lf%lf",&a[i].x,&a[i].y);a[i].num=i;double temp=a[i].x;a[i].x=(temp+a[i].y)/2;a[i].y=(temp-a[i].y)/2;}    sort(a+1,a+1+n,cmpx);qx[1]=a[1].x;Rep(i,2,n)qx[i]=qx[i-1]+a[i].x;dx[1]=a[n].x;DRep(i,n-1,1)dx[n-i+1]=dx[n-i]+a[i].x;    Rep(i,1,n)posx[a[i].num]=i;    sort(a+1,a+1+n,cmpy);qy[1]=a[1].y;Rep(i,2,n)qy[i]=qy[i-1]+a[i].y;dy[1]=a[n].y;DRep(i,n-1,1)dy[n-i+1]=dy[n-i]+a[i].y;    Rep(i,1,n)posy[a[i].num]=i;    Rep(i,1,n)    {        double reux=0;reux=(posx[i]-1)*a[posy[i]].x-qx[posx[i]-1]+dx[n-posx[i]]-(n-posx[i])*a[posy[i]].x;        double reuy=0;reuy=(posy[i]-1)*a[posy[i]].y-qy[posy[i]-1]+dy[n-posy[i]]-(n-posy[i])*a[posy[i]].y;        if(reux+reuy<ans||i==1)ans=reux+reuy;    }    printf("%.0lf",ans);    //for(;;);    return 0;}`

0 0