www.pudn.com > TJU.rar > ac1097.pas
program tju1097;
const
maxn=15000;
var
x,y,col:array[1..maxn]of longint;
count:array[1..maxn]of word;
n,r,i,cols,ans,f:word;
procedure qsortdot(s,t:word);
var
p,i,j,tx,ty:longint;
begin
if s>=t then exit;
p:=s+random(t-s+1);
tx:=x[p];ty:=y[p];x[p]:=x[s];y[p]:=y[s];
i:=s;j:=t;
repeat
while (ity) or (y[j]=ty) and (x[j]>tx)) do dec(j);
if i=j then break;x[i]:=x[j];y[i]:=y[j];inc(i);
while (i=t then exit;
p:=s+random(t-s+1);
tc:=col[p];col[p]:=col[s];
i:=s;j:=t;
repeat
while (i=tc) do dec(j);
if i=j then break;col[i]:=col[j];inc(i);
while (ir then exit;
inc(count[i],d);
if count[i]>ans then ans:=count[i];
end;
end;
begin
repeat
read(n,r);
for i:=1 to n do begin
read(x[i],y[i]);
col[i]:=x[i];
end;
qsortdot(1,n);qsortcol(1,n);
cols:=1;
for i:=2 to n do
if col[i]>col[i-1] then begin
inc(cols);col[cols]:=col[i];
end;
for i:=1 to n do
x[i]:=search(x[i]);
fillchar(count,sizeof(count),0);ans:=0;f:=1;
for i:=1 to n do begin
while y[i]-y[f]>r do begin modify(x[f],y[f],-1);inc(f);end;
modify(x[i],y[i],1);
end;
writeln(ans);
until seekeof;
end.