Pagini recente » Cod sursa (job #3166589) | Cod sursa (job #3292776) | Diferente pentru implica-te/arhiva-educationala intre reviziile 52 si 223 | Cod sursa (job #1996927) | Cod sursa (job #174815)
Cod sursa(job #174815)
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[i]<A[j]) 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[B[i]],' ');
max := max-1;
end;
close(f);
close(g);
end.