Cod sursa(job #636775)
Utilizator | Data | 19 noiembrie 2011 23:35:55 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 70 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.38 kb |
Program arena_crescator;
var fi,fo : text;
a,b,c : array[1..100005] of longint;
i,j,n,max,j1 : longint;
begin
assign(fi,'scmax.in'); reset(fi); readln(fi,n);
assign(fo,'scmax.out'); rewrite(fo);
for i:=1 to n do read(fi,a[i]);
c[n]:=0; b[n]:=1; max:=0;
for i:=n-1 downto 1 do begin
c[i]:=0; b[i]:=1;
for j:=i+1 to n do if (a[i]<a[j]) and (b[i]<b[j]+1) then begin
b[i]:=b[j]+1;
c[i]:=j;
if b[i]>max then begin
max:=b[i];
j1:=i;
end;
end;
end;
writeln(fo,max);
j:=j1;
while c[j]<>0 do begin
write(fo,a[j],' ');
j:=c[j];
end;
write(fo,a[j]);
close(fi); close(fo);
end.