Cod sursa(job #399184)

Utilizator RaddarDascalu Alexandru Raddar Data 19 februarie 2010 22:56:50
Problema Subsir crescator maximal Scor 35
Compilator fpc Status done
Runda Arhiva educationala Marime 0.94 kb
var n,i,j,max,x,y:longint;
        lung,a,poz:array[1..100000]of longint;
        f:text;

procedure mac1;
begin
        assign(f,'scmax.in');
        reset(f);
        readln(f,n);
        for i:=1 to n do read(f,a[i]);
        close(f);
        y:=0;
            for i:=1 to n do
            begin
                 max:=0;
                 for j:=1 to i-1 do
                 if(a[i]>a[j])and(max<lung[j])then max:=lung[j];
                 lung[i]:=max+1;
                 if lung[i]>y then y:=lung[i];
            end;
        assign(f,'scmax.out');
        rewrite(f);
        writeln(f,y);
        x:=1;
        for i:=1 to n do begin
        if(x=1)and(lung[i]=2)then begin
                                write(f,a[i-1],' ',a[i]);
                                x:=x+2;
                                end;
        if(lung[i]=x)and(x>2)then begin x:=x+1; writeln(f,' ',a[i]); end;
        end;

end;

begin
mac1;
end.