Cod sursa(job #680486)

Utilizator oancea_horatiuOancea Horatiu oancea_horatiu Data 15 februarie 2012 17:58:51
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.65 kb
var s,v,e,u:array[0..100001] of longint;
    m,n,i,j,max,maxi:longint;
    o,d:text;
begin
assign(d,'scmax.in');assign(o,'scmax.out');
reset(d);rewrite(o);
read(d,n);v[1]:=1;
for i:=1 to n do
  begin
    read(d,s[i]);
    for j:=i-1 downto 1 do
      if s[i]>s[j] then
        begin if v[i]<=v[j] then
          begin
            v[i]:=v[j]+1;u[i]:=j;
            if v[i]>max then begin max:=v[i];maxi:=i; end;
          end; end else if v[i]=0 then v[i]:=1;
  end;
writeln(o,max);
for i:=1 to n do
  begin
    e[i]:=s[maxi];
    maxi:=u[maxi];
    if maxi=0 then break;
  end;
for j:=i downto 1 do write(o,e[j],' ');
close(o);close(d);
end.