Cod sursa(job #742778)

Utilizator vasile_pojogaPojoga Vasile vasile_pojoga Data 1 mai 2012 14:50:24
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 1.04 kb
program subsir;
var n,i,j,max,k:longint;
    a,next,best:array[1..100000] of longint;
    b1:array[1..1 shl 17] of char;
begin
assign(input,'scmax.in'); settextbuf(input,b1); reset(input);
assign(output,'scmax.out'); rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
close(input);
for i:=n downto 1 do begin
         max:=0; k:=i;
         for j:=i+1 to n do
                if (a[j]>a[i])and(best[j]>max) then begin
                                                    max:=best[j];
                                                    k:=j;
                                                    end;
         best[i]:=max+1;
         next[i]:=k;
                        end;
max:=best[1]; k:=1;
for i:=2 to n do
        if best[i]>max then begin
                            k:=i;
                            max:=best[i];
                            end;
i:=k;
writeln(max);
while next[i]<>i do begin
                    write(a[i],' ');
                    i:=next[i];
                    end;
write(a[i]);
close(output);
end.