Pagini recente » Cod sursa (job #3125439) | Cod sursa (job #2155840) | Cod sursa (job #2880824) | Cod sursa (job #888853) | Cod sursa (job #680632)
Cod sursa(job #680632)
var f,g:text;
n,i,max,j,poz:longint;
a,lung:array[0..100000]of longint;
begin
assign(f,'scmax.in'); reset(f); assign(g,'scmax.out');rewrite(g);
read(f,n);
for i:=0 to n-1 do
read(f,a[i]);
lung[n-1]:=1;
for i:=n-2 downto 0 do
begin
max:=0;
for j:=i+1 to n-1 do
if a[i]<a[j] then if max<=lung[j] then max:=lung[j];
lung[i]:=max+1;
end;
max:=lung[0];
poz:=0;
for i:=1 to n-1 do
if max<lung[i] then begin max:=lung[i]; poz:=i;end;
writeln(g,max);
write(g,a[poz],' ');max:=max-1;
for i:=poz+1 to n-1 do
if (lung[i]=max)and(a[i]>=poz) then begin
write(g,a[i],' ');
poz:=i;
max:=max-1;
end;
close(f);
close(g);
end.