Pagini recente » Cod sursa (job #1743360) | Cod sursa (job #2782001) | Cod sursa (job #1999480) | Cod sursa (job #135993) | Cod sursa (job #1096070)
var a,a1: array[1..100000] of longint;
t,i,k1,max,max1,n: longint;
begin
assign(input,'scmax.in');
assign(output,'scmax.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
a1[n]:=1;
for k1:=n-1 downto 1 do Begin
max:=0;
for i:=(k1+1) to n do
if (a[i]>=a[k1]) and (a1[i]>max) then max:=a1[i];
a1[k1]:=max+1;
if a1[k1]>max1 then begin max1:=a1[k1]; t:=k1; end;
end;
writeln(max1);
write(a[t],' ');
for i:=t+1 to n do
if ((a[i]>=a[t]) and (a1[i]=max1-1)) then begin
write(a[i],' ');
max1:=max1-1;
end;
close(input);
close(output);
end.