Cod sursa(job #273044)

Utilizator MBlueGheorghevici Mihai MBlue Data 8 martie 2009 01:39:52
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 1.3 kb
type sir = array[1..100000] of longint;
     el1 = record
         val : sir;
         best : sir;
         tata : sir;
         end;
var el : el1;
    f:text;
    i,n,max,pozmax,poz:longint;

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;

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

begin
     assign(f,'scmax.in');reset(f);
     read(f,n);
     for i:=1 to n do read(f,el.val[i]);
     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;
     assign(f,'scmax.out');rewrite(f);
     writeln(f,max);
     afisare(pozmax);
     close(f);
end.