Cod sursa(job #342326)

Utilizator andrey932Andrei andrey932 Data 21 august 2009 12:38:47
Problema Subsir 2 Scor 36
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.71 kb
uses math;
var x,ad,nr,ad1:array[0..5000] of longint;
    i,j,a,b,n,jj:longint;
    t:text;
begin
assign(t,'subsir2.in'); reset(t);
readln(t,n);
for i:=1 to n do
  begin
    read(t,nr[i]);
    x[i]:=1;
    ad[i]:=i;
    for j:=i-1 downto 1 do
      begin
       if (nr[j]<nr[i]) then
        if (x[j]+1>x[i]) then
          begin
            x[i]:=x[j]+1;
            ad[i]:=j;
          end;


      end;
  end;
assign(t,'subsir2.out'); rewrite(t);
jj:=1;
for i:=1 to n do
  if (x[i]>x[jj] ) then jj:=i;
writeln(t,x[jj]);
j:=jj;

i:=1;
while x[j]>1 do
  begin
    ad1[i]:=j;
    j:=ad[j];
    i:=i+1;
  end;
write(t,j,' ');
for jj:=i-1 downto 1 do
  write(t,ad1[jj],' ');
close(t);
end.