Pagini recente » Cod sursa (job #569214) | Cod sursa (job #3179850) | Cod sursa (job #1643696) | Cod sursa (job #682199) | Cod sursa (job #697647)
Cod sursa(job #697647)
program sss;
var n,i,max,j,t:longint;
l,a:array[1..1000005] of longint;
f,g:text;
begin
assign(f,'scmax.in'); reset(f);
assign(g,'scmax.out'); rewrite(g);
readln(f,n);
for i:=1 to n do
read(f,a[i]);
l[n]:=1;
for i:=n-1 downto 1 do
begin
max:=0;
for j:=i+1 to n do
begin
if (a[j]>a[i]) and (l[j]>max) then
max:=l[j];
l[i]:=1+max;
end;
end;
max:=l[1];
t:=1;
for i:=2 to n do
if l[i]>max then
begin
max:=l[i];
t:=i;
end;
writeln(g,max);
write(g,a[t],' ');
for i:=t+1 to n do
begin
if (A[i]>a[t] ) and (l[i]=max-1) then
begin
write(g,a[i],' ');
max:=max-1;
end;
end;
close(f);
close(g);
end.