Cod sursa(job #174918)

Utilizator free2infiltrateNezbeda Harald free2infiltrate Data 9 aprilie 2008 12:57:47
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.73 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;

for i := n-1 downto 1 do begin
max := 0;

for j := i+1 to n do
if (A[j]>A[i]) and (B[j]>max) then max := B[j];
B[i] := max+1;
end;

max := B[1];
poz := 1;

for i := 2 to n do
if B[i]>max then begin
                 max := B[i];
                 poz := i;
                 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.