Cod sursa(job #174895)

Utilizator free2infiltrateNezbeda Harald free2infiltrate Data 9 aprilie 2008 12:40:27
Problema Subsir crescator maximal Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.7 kb
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.