Cod sursa(job #280800)

Utilizator MBlueGheorghevici Mihai MBlue Data 13 martie 2009 16:14:47
Problema Subsir crescator maximal Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 1.41 kb
type sir = array[1..100] of longint;
     el1 = record
         val : sir;
         best : sir;
         tata : sir;
         end;
var el : el1;
    f:text;
    i,n,max,pozmax,poz:longint;

procedure read1;
begin
     read(f,n);
     for i:=1 to n do read(f,el.val[i]);
end;

procedure afisare(n:longint);
begin
writeln(f,max);
if n<>0 then begin
   write(f,el.val[n],' ');
   afisare(el.tata[n]);
   end;
end;

function caut:longint;
var j:longint;
    ok : boolean;
begin
ok := false;
for j:=i+1 to n do
    if (el.val[i] < el.val[j]) and (el.best[i] < el.best[j]+1) then begin
       el.best[i] := el.best[j]+1;
       el.tata[i] := j;
       ok := true;
    end;
if ok then caut := j
   else caut := 0;
end;

begin
     assign(f,'scmax.in');reset(f);
     read1;close(f);

     el.tata[n] := 0;
     el.best[n] := 1;
     max := el.best[n];
     pozmax := n;

     for i:=n-1 downto 1 do begin
         el.best[i] := 1;
         poz := caut;
         if poz<>0 then begin
            if max<el.best[i] then begin
               max := el.best[i];
               pozmax := i;
               end;
         end
         else begin
              el.best[i]:=1;
              el.tata[i]:=0;
              end;
     end;
     for i := 1 to n do begin
         write(el.tata[i]);
     end;
     readln;
     assign(f,'scmax.out');rewrite(f);
     afisare(pozmax); close(f);
end.