Cod sursa(job #65361)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 8 iunie 2007 22:16:27
Problema Subsir 2 Scor 45
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.71 kb
var a,b:array[1..5000] of longint;
min,n,i,j,k,l,max,poz:longint;
begin
assign(input,'subsir2.in');
assign(output,'subsir2.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
b[n]:=1;
for i:=n-1 downto 1 do
        begin
        max:=0;
        for j:=i+1 to n do
                if (a[i]<a[j])and(max<b[j]) then max:=b[j];
        b[i]:=max+1;
        end;
max:=0;
for i:=1 to n do
        if b[i]>max then max:=b[i];
writeln(max);
poz:=1;
repeat
min:=maxlongint;
for i:=poz to n do
if (b[i]=max)and(a[i]<min) then   begin
                           min:=a[i];
        poz:=i;
        end;
write(poz,' ');
dec(max);
until max=0;
close(input);
close(output);
end.