BZOJ3210: Flower God's watering flower rally

Source: Internet
Author: User

Description

Under the guidance of the flower teacher, 4 each week has a rally activity, commonly known as "watering" activities.

For detailed watering activities, please see BZOJ3153

But that's not the point.

The flower God has a lot of questions, each problem has two reference coefficients: code difficulty and algorithmic difficulty

In order to prepare for the watering of the flower assembly, the flower God must find a problem that suits everyone best.

Now the flower God knows each person's code ability x and algorithm ability Y, a problem (code difficulty X algorithm difficulty y) to this person's unsuitable degree for Max (ABS (X–X), ABS (Y–y))

That is, whether too difficult or too simple will cause the topic is not suitable to do (if all according to the Flower God himself, the absolute full-blown 0 rhythm, too simple, it does not show the power of the Flower God)

Of course not every time as the flower of God's wish, there is not necessarily a problem for all, so to make all the sub-moderate sum as low as possible

Flower God out of 100001*100001 problem, each problem code difficulty and algorithmic difficulty are 0,1,2,3,......,100000

Input

The first line is a positive integer n, which means that the flower God has n students, and the flower God wants to choose a problem for the N students.

The next n lines, two spaces separated by each line of integer x[i],y[i], represent the student's code and algorithm capabilities

Output

An integer that represents the smallest amount of inappropriate sums

Sample INPUT3

1 2

2 1

3 3

Sample Output
3

HINT



For 100% of data, n<=100000,0<=x[i],y[i]<=100000

Converting (x, y) to (x+y,x-y) converts the Chebyshev distance into a Manhattan distance (push it yourself), and a, B Chebyshev is half the distance from a ' and B ' Manhattan. Then you can separate x, Y, and sort the median. Note that if the last selected optimal x and Y return is not an integer, choose an optimal scheme around the top and bottom of it. There is this problem do not know how to optimize the IO is not used.
#include <cstdio>#include<cctype>#include<queue>#include<cmath>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i;i=next[i])using namespacestd;Const intBuffersize=1<< -;Charbuffer[buffersize],*head,*Tail;inlineCharGetchar () {if(head==tail) {        intL=fread (Buffer,1, Buffersize,stdin); Tail= (Head=buffer) +l; }    return*head++;} InlineintRead () {intx=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;} typedefLong Longll;Const intmaxn=100010;intn,x[maxn],y[maxn];ll Solve (intXintY) {ll ans=0; Rep (I,1, N) ans+=abs (X-x[i]) +abs (yY[i]); returnans;}intMain () {n=read (); Rep (I,1, N) {        intA=read (), b=read (); X[i]=a+b;y[i]=a-b; } sort (x+1, x+n+1); Sort (y+1, y+n+1); intx=x[n+1>>1],y=y[n+1>>1]; if(~ (x^y) &1) printf ("%lld\n", Solve (x, y)/2); Elseprintf"%lld\n", Min (min (Solve (x1, Y), Solve (x,y-1)), Min (Solve (x+1, Y), Solve (x,y+1)))/2); return 0;}
View Code

BZOJ3210: Flower God's watering flower rally

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.