Pagini recente » Cod sursa (job #2972102) | Cod sursa (job #2486860) | Cod sursa (job #2667974) | Cod sursa (job #2182715) | Cod sursa (job #268369)
Cod sursa(job #268369)
var
i,j,n,max,p:longint;
f:text;
poz,a,l:array[1..100000] of longint;
Begin
assign(f,'scmax.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;
{ max:=L[1];p:=1;
for i:=2 to n do
if max<L[i] then begin
max:=L[i];
p:=i;
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.