Pagini recente » Cod sursa (job #18172) | Cod sursa (job #551893) | Cod sursa (job #9190) | Cod sursa (job #60665) | Cod sursa (job #34665)
Cod sursa(job #34665)
#include<stdio.h>
long long int n,dx,dy,i,a,b,x[50100],y[50100],l,r,sl,sr,ul,ur,sln,uln,srn,urn,sol;
int main()
{
FILE *f,*g;
f=fopen("tribute.in","r");
g=fopen("tribute.out","w");
fscanf(f,"%lld%lld%lld",&n,&dx,&dy);
for(i=1;i<=n;i++)
{ fscanf(f,"%lld%lld",&a,&b);x[a]=x[a]+1;y[b]=y[b]+1;}
l=0;sl=x[l];ul=0;sln=sl+x[l+1];uln=ul+sl;
r=50000;sr=x[r];ur=0;srn=sr+x[r-1];urn=ur+sr;
while((r-l)>dx)
{ if(sln<=sr) { l++;sl=sln;ul=uln;sln=sl+x[l+1];uln=ul+sl;}
else { r--;sr=srn;ur=urn;srn=sr+x[r-1];urn=ur+sr;}
}
sol=sol+ul+ur;
l=0;sl=y[l];ul=0;sln=sl+y[l+1];uln=ul+sl;
r=50000;sr=y[r];ur=0;srn=sr+y[r-1];urn=ur+sr;
while((r-l)>dy)
{ if(sln<=sr) { l++;sl=sln;ul=uln;sln=sl+y[l+1];uln=ul+sl;}
else { r--;sr=srn;ur=urn;srn=sr+y[r-1];urn=ur+sr;}
}
sol=sol+ul+ur;
fprintf(g,"%lld\n",sol);
fcloseall();
return 0;
}