Pagini recente » Cod sursa (job #2000740) | Cod sursa (job #680235) | Cod sursa (job #325036) | Cod sursa (job #2835913) | Cod sursa (job #268370)
Cod sursa(job #268370)
var
i,j,n,max,p:longint;
f:text;
poz,a,l:array[1..100000] of longint;
Begin
assign(f,'max.in');
reset(f);
readln(f,n);
for i:=1 to n do
read(f,a[i]);
close(f);
L[n]:=1;
poz[n]:=-1;
max:=L[n];
p:=n;
for i:=n-1 downto 1 do
begin
L[i]:=1;
poz[i]:=-1;
for j:=i+1 to n do
if (a[i]<a[j]) and (L[i]<1+L[j]) then
begin
L[i]:=1+L[j];
poz[i]:=j;
end;
if max<L[i] then begin
max:=L[i];
p:=i;
end;
end;
assign(f,'scmax.out'); rewrite(f);
writeln(f,max);
i:=p;
while i<>-1 do
begin
write(f,a[i],' ');
i:=poz[i];
end;
close(f);
End.