Mai intai trebuie sa te autentifici.

Cod sursa(job #262992)

Utilizator 05_YohnE1 La5c01 05_Yohn Data 19 februarie 2009 20:21:51
Problema Subsir crescator maximal Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 1.2 kb
var v,a,tata:array[1..100000]of longint;
    f:text;
    i,n,max,pozmax,poz:longint;

function caut(m:longint):longint;
var ok:boolean;
    i:longint;
begin
ok:=false;
for i:=m+1 to n do if v[m]<v[i] then begin
                                     ok:=true;
                                     break;
                                     end;
if ok then caut:=i
      else caut:=0;
end;

procedure afisare(n:longint);
begin
if n<>0 then begin
        write(f,v[n],' ');
        afisare(tata[n]);
        end;
end;

begin
assign(f,'scmax.in');reset(f);
read(f,n);
for i:=1 to n do read(f,v[i]);
close(f);
tata[n]:=0;
a[n]:=1;
max:=a[n];pozmax:=n;
for i:=n-1 downto 1 do begin
    poz:=caut(i);
    if poz<>0 then begin
                   a[i]:=a[poz]+1;
                   tata[i]:=poz;
                   if max<a[i] then begin
                                    max:=a[i];
                                    pozmax:=i;
                                    end;
                   end
              else begin
                   a[i]:=1;
                   tata[i]:=0;
                   end;
end;
assign(f,'scmax.out');rewrite(f);
writeln(f,max);
afisare(pozmax);
close(f);
end.