why i got WA?????
Posted by
qwt 19 Mar 2002 18:13
const
maxn=100000;
maxtime=30000;
var
list:array[0..maxn,1..2] of integer;
a:array[0..maxtime] of longint;
v:array[0..400] of longint;
q,max,i,j,k,n,x,y:longint;
procedure sort(x,y:longint);
var
i,j,k,a,b:longint;
begin
if y-x<=0 then exit;
if y-x=1 then begin
if (list[x,2]>list[y,2])or((list[x,2]=list[y,2])and(list[x,2]>list
[y,2])) then begin
list[0]:=list[x];
list[x]:=list[y];
list[y]:=list[0];
end;
exit;
end;
k:=random(y-x)+x;
a:=list[k,1];b:=list[k,2];
i:=x;j:=y;
while i<j do begin
while ((list[i,2]<b)or((list[i,2]=b)and(list[i,1]<a)))and(i<j) do
inc(i);
while ((list[j,2]>b)or((list[j,2]=b)and(list[j,1]>a)))and(i<j) do
dec(j);
list[0]:=list[i];
list[i]:=list[j];
list[j]:=list[0];
end;
sort(x,i-1);sort(i+1,y);
end;
begin
randomize;
readln(n);
max:=0;
for i:=1 to n do
readln(list[i,1],list[i,2]);
sort(1,n);
fillchar(a,sizeof(a),0);j:=1;fillchar(v,sizeof(v),0);
for i:=1 to n do
if a[list[i,2]]+v[list[i,2] div 100]<a[list[i,1]-1]+v[(list[i,1]-
1) div 100]+1 then begin
q:=a[list[i,1]-1]+v[(list[i,1]-1) div 100]+1;
for j:=list[i,2] to (list[i,2] div 100+1)*100-1 do a[j]:=q;
for j:=list[i,2] div 100+1 to 400 do v[j]:=q;
end;
writeln(a[list[n,2]]+v[list[n,2] div 100]);
end.