Cod sursa(job #680651)

Utilizator andreiseiceanSeicean Andrei andreiseicean Data 15 februarie 2012 20:00:57
Problema Subsir crescator maximal Scor 65
Compilator fpc Status done
Runda Arhiva educationala Marime 0.91 kb
var f,g:text;
    n,i,max,j,poz:longint;
    a,lung:array[0..100000]of longint;
    buf1,buf2:array[1.. 1 shl 17]of char;
begin
assign(f,'scmax.in'); settextbuf(f,buf1); reset(f);
assign(g,'scmax.out'); settextbuf(g,buf2); rewrite(g);
read(f,n);
for i:=0 to n-1 do
   read(f,a[i]);
lung[n-1]:=1;
for i:=n-2 downto 0 do
   begin
      max:=0;
      for j:=i+1 to n-1 do
        if a[i]<a[j] then if max<lung[j] then max:=lung[j];
      lung[i]:=max+1;
    end;
max:=lung[0];
poz:=0;
for i:=1 to n-1 do
   if max<lung[i] then begin max:=lung[i]; poz:=i;end;
writeln(g,max);
write(g,a[poz],' ');max:=max-1;
for i:=poz+1 to n-1 do
   if (lung[i]=max)and(a[i]>poz) then begin
                                        write(g,a[i],' ');
                                        poz:=i;
                                        max:=max-1;
                                      end;
close(f);
close(g);
end.