Pagini recente » Cod sursa (job #957431) | Cod sursa (job #2233168) | Cod sursa (job #1944871) | Cod sursa (job #2655898) | Cod sursa (job #174895)
Cod sursa(job #174895)
program scmax;
type vect = array [1..100000] of longint;
var A,B : vect;
m,n,i,j,max,poz : 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]);
B[n] := 1;
max := 1;
poz := n;
for i := n-1 downto 1 do begin
B[i] := 0;
for j := i to n do
if (A[j]>A[i]) and (B[i]<B[j]) then B[i] := B[i]+1;
B[i] := B[i]+1;
if B[i]>max then begin
max := B[i];
poz := i;
end;
end;
writeln(g,max);
for i := poz to n do
if B[i]=max then begin
write(g,A[i],' ');
max := max-1;
end;
close(f);
close(g);
end.