Pagini recente » Cod sursa (job #789345) | Cod sursa (job #92809) | Cod sursa (job #2699489) | Cod sursa (job #2828492) | Cod sursa (job #1091466)
program subsir_crescator;
var v,l:array[1..100001] of longint;
bufin,bufout:array[1..100000] of byte;
n,i,k,max,t:longint;
f,g:text;
begin
assign(f,'scmax.in'); reset(f);
assign(g,'scmax.out'); rewrite(g);
SetTextBuf(f,bufin);
SetTextBuf(g,bufout);
readln(f,n);
for i:=1 to n do
read(f,v[i]);
l[n]:=1;
for k:=n-1 downto 1 do
begin
max:=0;
for i:=k+1 to n do
if (v[i]>v[k]) and (l[i]>max) then
max:=l[i];
l[k]:=1+max;
end;
max:=l[1];
t:=1;
for k:=1 to n do
if l[k]>max then
begin
max:=l[k];
t:=k
end;
writeln(g,max);
write(g,v[t],' ');
for i:=t+1 to n do
if (v[i]>v[t]) and (l[i]=max-1) then
begin
write(g,v[i],' ');
max:=max-1;
end;
close(f);
close(g);
end.