Pagini recente » Cod sursa (job #3180867) | Cod sursa (job #2807058) | Cod sursa (job #2975112) | Cod sursa (job #2680412) | Cod sursa (job #577951)
Cod sursa(job #577951)
var a:array[1..100000] of longint;
l:array[1..100000] of integer;
max,k,n,i,j:longint;
begin
assign(input,'scmax.in');
reset(input);
assign(output,'scmax.out');
rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
l[n]:=1;
for i:=n-1 downto 1 do
begin
max:=0;
for j:=i+1 to n do
if (l[j]>max) and (a[i]<=a[j]) then max:=l[j];
l[i]:=1+max;
end;
max:=l[1];k:=1;
for i:=2 to n do
if l[i]>max then
begin
max:=l[i];
k:=i;
end;
writeln(max);
write(a[k],' ');j:=k;
for i:=k+1 to n do
if (l[i]=max-1) and (a[i]>=a[j]) then
begin
write(a[i],' ');
dec(max);
j:=i;
end;
end.