Pagini recente » Cod sursa (job #2175048) | Cod sursa (job #1938816) | Cod sursa (job #2295362) | Cod sursa (job #2462124) | Cod sursa (job #749909)
Cod sursa(job #749909)
var a,l:array[1..100] of integer;
n,i,j,max,k,mx,p:integer;
begin
assign(input,'scmax.in');reset(input);
assign(output,'scmax.out');rewrite(output);
read(n);
for i:=1 to n do read(a[i]);
l[n]:=1;
for i:=n-1 downto 1 do begin
l[i]:=0;
max:=0;
for j:=i+1 to n do
if (l[j]>max) and (a[i]<a[j]) then max:=l[j];
l[i]:=max+1;
if l[i]>mx then begin
p:=i;
mx:=l[i];
end;
end;
writeln(mx);
write(a[p],' ');
k:=a[p];
dec(mx);
for i:=p+1 to n do
if (a[i]>k) and (l[i]=mx) then begin
write(a[i],' ');
k:=a[i];
dec(mx);
end;
close(output);
end.