Cod sursa(job #676160)

Utilizator iulia_n2007Tica Iulia iulia_n2007 Data 8 februarie 2012 19:39:25
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.87 kb
var f,g:text;
    a,b,c:array[1..100000] of longint;
    m,max,e,i,j,n:longint;
    ok:boolean;
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]);
max:=0;
e:=0;
for i:=1 to n do
 begin ok:=false;
       for j:=i downto 1 do
         if (a[j]<a[i]) and (b[i]<=b[j]) then begin b[i]:=b[j]+1;
                                                    c[i]:=j;
                                                    if b[i]>max then begin max:=b[i]; e:=i;  end;
                                                    ok:=true;
                                              end;
      if ok=false then b[i]:=1;
  end;
writeln (g,max);
b[1]:=a[e];
m:=1;
while c[e]<>0 do
 begin e:=c[e];
       m:=m+1;
       b[m]:=a[e];

 end;
for i:=m downto 1 do
 write (g,b[i],' ');

close (f);
close (g);

end.