[bzoj3210][Chebyshev Distance] Flower god's watering party

Keywords: less IE

Description

Under the guidance of the flower teacher, there is a gathering every 4 days, commonly known as "water" activities.

See BZOJ3153 for details of water activities

But that's not the point

There are many fantasy questions, each with two reference coefficients: code difficulty and algorithm difficulty.

Flower gods must find a topic that suits everyone as best as possible in order to prepare for a flower-watering party

Now Flower knows everyone's code ability X and algorithm ability y. One question (code difficulty X algorithm difficulty Y) is Max (abs (X - x)
, abs ( Y – y ) )

That is to say, whether it is too difficult or too simple, it will make the title unsuitable for you to do (if you set it all according to the capabilities of the goddess themselves, the rhythm of the absolute all-round explosion is too simple, it will not show the power of flourishing).

Of course, not every time, there is not necessarily a question for everyone, so make the sum of all people's inadequacies as low as possible

Flower God created 100001*100001 questions, each of which had code and algorithm difficulty of 0, 1, 2, 3,..., 100,000

Input

The first line has a positive integer N, indicating that there are N students in the flower god. The Flower God wants to choose a question for N students.

Next N lines, an integer x[i],y[i] separated by two spaces on each line, indicate the student's code and algorithm capabilities

Output

An integer representing the smallest improper moderate sum

Sample Input

3

1 2

2 1

3 3

Sample Output

3

HINT

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

Problem

I thought for a while last night and didn't come up with it.
Come this morning
suddenly
Is this not the Chebyshev distance
Turn Manhattan Distance Strongly
Scan once for median
The example tells me with good conscience that Chebyshev may not be the whole point...
Then you'll sweep the four dots next to him all over.
Why is this data so watery?
Should the answer not be less than 100,000?

/*
:    .                                                                                                                  
:                                                                                                                       
i                                                                                                                       
i    .                                                                                                                  
i                                                                                                                       
:    .                                                                                                                  
i    .                                                                                                                  
i    .                                                                                                                  
i                                                                                                                       
:        .                                                                                                              
i  .  i  i :     . .    .   .     .       . .           ..    .                                   .          .          
.     .  . .       .                      .   .      .                                                          .       
:   qQ  .   v2d   .  i: ..:ij.iBE .i            EBj        .irrivri.::iiiir7r.                       .    SPd.  :       
i  UQB    .BBBBE     BBBQBBBBLiBB.1BBi    :X:   BBu    .   .KBBBBBBBBBBBBBBBQv                          :BBBBB          
. iBY PD. BBY vBBv.  ..:gB1   rBM  7B1    RQP   MBgvPPQBB          uRq.        ..                 .    jBBQ.BBBr        
:.BBrQBBBBBL   iQBB7:777gBSYvrKBBv:v71r..YPBBBBBBBBBBEBBB    7RBZQdBBBdEgBQE                         1QBB1   QBBB:      
.:BBBBJ.qBBDBBBBBBBvrQBQBBBBBBBBBBBBBgg5UBBBBriiBQ1   rBB  .:.:i. :KQBi ..::    :.. . . .   .....  UBBB5  UJ: rBBBBXi   
.  IQY     i:.:..       YBs   :BB   IE.   XBZ   QBs   7BB  rBBBBQBBBBBBBQBBBBq BQBBBBBBBBBBBBBBBBviBBE.  .BBZ   .BBgi.  
. BBBQSJ.Kb5BQgRBPv :5gQBBBQBB:YBvrBBd    QBE   BBdiBBBB5      .BB     uBs     iririiiriir7iii77i. ii    .BBD  .        
. uQ5Sv .BB::i::QBU  BBQMBK.   7BBBP.     DBq   QB1 DQ7.L. sBBdQBBMBBBQBBBBBQDi                           BB5           
.    ...:BB     KBJ     uB1   UBBBL  QBL  RQb   i:.     BBPvi.UBBuY7v7iQBqrrur.                           BBE   .       
:LBBBBBBJQBBBBQBBBJ  :rvBBu:BBB1jBBPbBB   SBBZIvSUguJXRBBB:  7QBB      BBu     ..                         BBQ           
r.XX... .QBIYXDJBB1  qBBBBi ir   rMQBQ.   .sPBBBBBBBBRBBD7  XBBi       dB1. .  ..                        .BBg           
i                .                   .                           . . .         ..                         ... .         
:                                                                                                                       
i    .                                                                   .                                              
i                                                                                                                       
i    .                                                                                                                  
i                                                                         :r:.                                          
i    .                                                                .  vKKSj. .                                       
r                                                                 ..    :B: js  .                                       
i    .                                                             .    rK .S:                 :::                      
r                                                                       :v LS             .  ibi7gv   .                 
i                                                                       :Ligi               .QJ :g7  .                  
.      ...5d:  .                                                        i2Sd               rb. vj:      .               
.   .7:r27DBi                                                      .    .Bb:     .        7K..Ps                        
uij1Pdr.  ri                                                       .     Sq              :Kj7Ii .  .     :v:            
UvY:     7P. .                                                     .     .7             .vIqX. ..  .    .dBRS7.         
.    .   qP     . .       .  ..                                       .     .  ..        :r.            .qi :2ZPi       
.    .   gs     .    .:K2  .          .irvIs75K5XEKMKgZsD522YLri.              iBB1i                     Pr   .2r       
i       iS:        .isjjQ.    .:rs5KPPMBBBZdBBgi:7Rd7XBBBRSMBBDZQZSr.        rDYiiYdQSr.                 dY             
:       Ys      .iXbi.  7: 7v5gQZqPEKXUIjUIdbr   ur    jRQr1E:  .rJgBBDL:   iEv     .sdD5Yi.             MX  .   .      
i       Si   .vU57i   .ibQBBgMPI175XUvsq5LBj   :Li.     jQLJ:  .    .rdBBQsYL           :r1ISv:         .gu    .        
:   .. iU  r5Qu.   :sBBD7qDqbbijPj5ISXv22UK   .BY .     .gSP: .q:      rBBBBS    .   .      .7KEYi.      qv    .        
.      qBsY1i   :IqBZqI2rUXLXQPrYjIuED2jZPv.  KI .  .    .BR. rd        .bBUBQu.          .    .isZK1:   5s             
:      vPv.  .idDBEP1XYKXQR1r5d2SdPqEDv7IEY  Yv    .      KB.:U.  :Ui    .BJUBBB1        .         rXqIrrB2    .        
v           rQDM1dj7SM1qIuPgXJKS2sKU5urLDMr :Bi   .  .dBMi7BPYJ 1PKL:     BjKIUPBB1       .       .   :irMX             
i  .     .vKDDr1YREIPgv1qS1Qbju1IS2US5vUZBu sr .    :BBBBdXMDMgjv.   :    guJsP7rQgU:                    JdrsSv:        
7       rQREJ5u2vuKv5dXKKPXqqXK1PSSqP2USqqBDj    .  7QBQRPQriQg:..v7i:.   MqEXBs72DQB:              .iYYr..iPRJ         
7  .  .MRB221QqKrYSSXdXXuBZuSguL1sPMDQQDPPgBi    .  :RBBMB5  PELBBBj     vP.  irRBgRPEv           .Ju7ivv7vLi.   .      
:    7DQUdSPqgIqUsKSYv5Si2PrruJSBZR5r::   :Z:        .irvX::qPPZMBBQgs  .Xs      LPuXBBi         :Dd2rLsr.      .       
i   YBZ7Lg2bUPLb172Xr7PQvJuuuMBbX7.       .uRu.         :QEBQRRBZgggQBSrY.         :SQQX         :27:.       .          
i .EP2PX1qJYIPuu5I2g2uB5YXbDZPJ   .rr.  .   7gZU7r7vYvvvJqBQRBMdgDMgBQQr            r5BBr                               
 .gB2LgEsPPuKE2IrM5Iu1U2JXgS.     :7vvvsYLL7. .rs77JJr.  JBQDBbdEZBRgBP      . .YIUvirvBQ:   .                          
XQQSqgDJ7qg5bPXqLd1bQ2JQB2.              ..:7Lv7:        iBQSREEBQQRBP:     iSPL7.     rBu                              
QgUjEE2qJbKsjX2duqYKr5BS.      ..             .rYr.       dBQBZBQBKgM. .  rZ2:          jEi                             
vJdPIJI5UPSYKb5uLbLSDEu       .                            :BBgBPEBr  .  ....         . iBK.                            
YvLb7K5L7ubsjgJuuSsPQ7  .....:iiirr77v7vrv1PXU77rr::.            :E.  .           .. ..  sgi                            
LuKQrsSd5XQPqSij7bBu    :ivu5J7i::::::::::i::.::iri..            :Ei.     ..i715qLPdUqS. iBi     .                      
7UPBv2IPqP1IdXLZZPr   .                                .         .sY       .ir:.     ..  .QE  ..                        
UsJRubSv7ggUJr1Qg:                             ..                 r5                      vd.                           
d5YPrSqX7QIvPRBX.  .  .            ..:i777r7vJvr:      .         .rZ  .                 .iE5rr                          
2LKXj2E17DjSMSQi          ..ii7uqS522J7:.....              ..     7Z.    .  .75Y::.  7KdBZEXXBQ:                        
r7PQqdEjJEPJuZJ       iIPK1j7:.:.         .:i:......              :P        .iLuvPSsXQbr     .JBP                       
sLPP1uqs2XR7JQ:       .:i.        .:71ZBBBQEDDMbdMBBBdui:         rZ.               .          bB.                      
UUqK7vSIv5PuDg                .YdQBBBBQBMESJ777s1bPdEgRQBBRUi.    .5       .                  .gq                       
vLZPvvbKLdSIBv          .   1MBRQBBBMEbZPvgBRJrLY7Uj2J7rvPDQBBgUY722            ...       ..  iBJ                       
irIKvUPI7M1SRi     .  .   7BB1JUvSd1Y512IYSBMKLPv1XirsivvUKgDgBBBBBBKr:.                  ..  uE.                       
D2KIJ5D17EPdd.  .        qBJv.ivivYi7JvrLrLEgbbP1PE:71sS5sDq7vDQD2qbgBBBMJi                  rR7                        
vJPbvJq2YgEQ2           .BP.L7ijIEuiivr7vii1PKgg5dRjXgUSujJ7JgJ7Piru1UKMBBQM2i             .2I:.                        
vrXP1Xg2vJjbL    .  .   sBBuXI1gBgE2SI7vIrrsIiSISdBSEZ1bggQv7Es:U77YLirugggDBBBgKUJrri:.:7IEP.                          
XU1UubPuLu7LY    .     :5RBgUBBPPdggBEUdqIKXviuJrYdPPq2PKKBqY1jrj75I1LL7UXZBBdPEQBP7jIIdKSBB.  .                        
sIDbX5X5KRBSE         .ZXLXI7q57UJ5IRUUZP5KZguivSv1S55bS12BMBjJ7dXBgZIqr7dqMEPBEQQ:       KB7         ...       ..      
PU7v5MPJ7KZPD         iBbU7v77:r7irYdIud5KqZPsrs2vYUsJuPP5SLKgQdEEgdPgMX7qvI5DXbMX       :BQ                            
511sSdZXI51vg.     .  LgXgU77iir5dddBMMBBBP5dP52S2gBQ2vL22RdBQBPQP15SdMR1Jivrr:MBr       SBv   .jDBMbuv:      ..        
vU52sujjUEq1E.   . .  2MrBDU5PQBZP7.:..irDQQPdBBRqi.      .:jXQMBPrIjXXBP1iuii.BE       .BX  rSQK:...i1dX7.             
KJ1svuqsrEgPK      .  v1rDQDBj:.          .LQBS.              .JBE.r7555RbbK55PBr    .  Kg  7QM.        7BBv            
PXdEu5PsLKv5di        7E1dKi                :J.                 :gg1iq1LsQRRYuBP   .r  KQi iBg           .2Q5.  .       
IjPP1ID5UJYdBY        rBBS    .                 .                :BErj7YU5ZPdBZ       vBv :Rd              IBi          
2UKK7JPXuIgQBb    .    bBi     .         .   .           .        EBPYv7srIKBB       vBr  sBi    .         .B1          
vvbb15d5bSPLPB:   .    rB:    ..          .                       :qBKQvYLJRK       iQ2 :ZBBr   .           Rv .        
SY57vDIKZLuuKBi        .BB.    .   .                             . bBXgudD5v      .2BBgqqbgBJ   .    ...   .E5          
v75vYqPPq5KPjJE:  .     iBBr    .                                 .BMvBQEv:       BBq1EsSQS5Bi  .   .      :BL          
vUUs7YuJrXJd7:BP     .   .PQqv:                          ..  .:77juBQJsi        rBQYiJU1JX5PRb:           vBL    .      
dZsY55RS1qjdqrBBL          .JPMRP77.   .:.....:.:i7vjuSqEEbXqqquL7. .         .jBQJvdR5vuuuJ5BBq:       isBB  . .       
BQ7v1KDu5qYSqsJgQ:             .r7IEPUs11uj25X21JJri::...                    7QB1rPQY2duIQKXZJ7BBdu7:isDZ5:    ..       
LYRgsvSUPqX1UUI2Bd.                                                       ii2MEgI7dRSJ1sSBX7SPXsPZBBXr77.               
 vBB1PBZMQggZDZMXgBBDgMRbbEQQRZPZRPKSPbDRBDKujsuYv25Ys2qSEPDMMddZgZMQBBBgQBQEPsqXJSqsIP52M5UPPsvERZi                    
s5QgPQBIDMMDgDgDgBBgEBBBBBBQQBBBBQBBBBBQQBBBBBBBBQBBBBBQBBBBBBBBBQBBBBBBBMBQgESDDSEKUPgU2qSqUrPBBv.   .                 
rrPBBgMDMQRRMQgQDMQBQBMgRQggDgRBBBgZgBBBQBBBBBBBBBBBBBS:     ..vbBBBQBQMbSQQMEYSuLI5uPKv1D77PBBXi      ...              
i LdMdKKqqPgZSgd1PZPSLXPXSZZXPZIQZJ5EKdDgMMdqYr.::.:bB:          LBXIQBKPgBquP2PZuUuUSXj5ZqXBB7                         
i:BP2j:vYs7q5sZI:2uvv7Ss7UYKs51r51rJLjDg7:          .BvPPgX1vrii:2Qi  vBbIMQuZrsDP55uu2XYdBQU:   .                      
rPBLJ27PXu7SP2QIvSJsPKgYPPisXq1Lg51ZBdr             2Q: .. .qBU.:vbv.  :IQBqiSs2KYLudKv7QQb.                            
BBXr7P1PXXsPSjD5757YPPE1JJiXPZj7sSQK:                1v     iBu   g7 .   iDBPQsIPuIP7vZB1.                       .      
MuiK7uKKj11Pj:S1UbuJXv2JJSKKLU2rSgX  .....:::...::.: .Bd..i.:bj .SB7 .::  KBgMv1gu2KqDBZ:  .:ii:ri::iiirrrviii7i.        
*/
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define LL long long
using namespace std;
LL ans;
int A[100005],B[100005];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		A[i]=x+y;B[i]=x-y;
	}
	sort(A+1,A+1+n);sort(B+1,B+1+n);
	int md1=(n+1)/2,md2=(n+1)/2;
	if((A[md1]+B[md2])%2==0)
	{
		for(int i=1;i<=n;i++)ans+=abs(A[md1]-A[i])+abs(B[md2]-B[i]);
		printf("%lld\n",ans/2);
	}
	else
	{
		int xpos=A[md1]-1,ypos=B[md2];LL hh=0;
		for(int i=1;i<=n;i++)hh+=abs(xpos-A[i])+abs(ypos-B[i]);
		ans=hh;
		xpos=A[md1]+1;ypos=B[md2];hh=0;
		for(int i=1;i<=n;i++)hh+=abs(xpos-A[i])+abs(ypos-B[i]);
		ans=min(ans,hh);
		xpos=A[md1];ypos=B[md2]-1;hh=0;
		for(int i=1;i<=n;i++)hh+=abs(xpos-A[i])+abs(ypos-B[i]);
		ans=min(ans,hh);
		xpos=A[md1];ypos=B[md2]+1;hh=0;
		for(int i=1;i<=n;i++)hh+=abs(xpos-A[i])+abs(ypos-B[i]);
		ans=min(ans,hh);
		printf("%lld\n",ans/2);
	}
	return 0;
}

Posted by waol on Mon, 06 May 2019 01:25:39 -0700