Cod sursa(job #582072)

Utilizator DDeidaraSzasz Tamas Csaba DDeidara Data 14 aprilie 2011 20:43:35
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.97 kb
type sorozat=array[1..100000] of longint;
var
        a,hossz,indx:sorozat;
        n,i,j,max:longint;
        f:text;

procedure visszakeres(k:longint);
begin
        if indx[k]<>0 then begin
        visszakeres(indx[k]);
        write(f,a[k],' ');
        end else write(f,a[k],' ');
end;

begin
        assign(f,'scmax.in');
        reset(f);
        readln(f,n);
        for i:= 1 to n do begin
                read(f,a[i]);
                hossz[i]:=1;
                end;

        for i:=2 to n do
                for j:=1 to i-1 do
                        if (a[j]<a[i]) and (hossz[i]<=hossz[j]) then
                        begin hossz[i]:=hossz[j]+1;
                              indx[i]:=j;
                        end;

        max:=1;
        for i:=2 to n do if hossz[max]<hossz[i] then max:=i;

        close(f);
        assign(f,'scmax.out');
        rewrite(f);
        writeln(f,hossz[max]);
        visszakeres(max);
        close(f);
end.