Why WA???????????????????!!!!!!!!!!!!!!!!!!!!!!!!
Послано
Cosine 18 сен 2003 20:20
{$m 65520,0,655360}
const maxn=30000;
type arr=array [1..2] of integer;
var f:array [0..maxn] of integer;
a:array [0..maxn] of arr;
n:integer;
procedure init;
var i:integer;
begin
readln(n);
for i:=1 to n do read(a[i,1],a[i,2]);
a[0,1]:=0; a[0,2]:=0;
fillchar(f,sizeof(f),0);
end;
procedure qsort(l,r:integer);
var mid,pl,pr:integer;
k:arr;
begin
mid:=(l+r) div 2;
k:=a[mid];
pl:=l; pr:=r;
a[mid]:=a[pl];
while pl<pr do begin
while (pl<pr) and (a[pr,1]>=k[1]) do dec(pr);
a[pl]:=a[pr];
while (pl<pr) and (a[pl,1]<=k[1]) do inc(pl);
a[pr]:=a[pl];
end;
a[pl]:=k;
if l<mid-1 then qsort(l,mid-1);
if mid+1<r then qsort(mid+1,r);
end;
procedure main;
var i,j:integer;
max:integer;
begin
f[0]:=0; f[1]:=1;
for i:=2 to n do begin
max:=-1; f[i]:=-1;
for j:=1 to i-1 do if f[j]>f[i] then f[i]:=f[j];
for j:=1 to i do if (a[i,1]-a[j,2]>=1) and (f[j]>max) then max:=f
[j];
if max+1>f[j] then f[j]:=max+1;
end;
end;
begin
init;
qsort(1,n);
main;
writeln(f[n]);
end.