Cod sursa(job #632056)
Utilizator | Cont vechi Buzu_Tudor_Ro | Data | 10 noiembrie 2011 10:38:40 |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 45 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.31 kb |
Program subsir;
var fi,fo:text;
a,l:array[1..100000] of longint;
i,j,max,poz,n: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]);
l[n]:=1;
max:=0;
for i:=n-1 downto 1 do begin
max:=0;
for j:=i+1 to n do
if (a[i]<a[j]) and (max<l[j]) then max:=l[j];
l[i]:=max+1;
end;
for i:=1 to n do if l[i]>max then begin max:=l[i]; poz:=i; end;
writeln(fo,max) ;
write(fo,a[poz],' '); i:=poz;
while i<=n do begin j:=i+1;
while (j<=n) and (l[j]=max-1) do if (a[i]<a[j]) then begin
write(fo,a[j],' ');
max:=max-1;
j:=j+1;
end
else j:=j+1;
poz:=i;
i:=i+1;
end;
close(fo); close(fi);
end.