Cod sursa(job #268373)
Utilizator | stancu vlad valytgjiu91 | Data | 1 martie 2009 10:49:28 |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 70 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.95 kb |
var
i,j,n,max,p:longint;
f:text;
poz,a,l:array[1..100000] of longint;
Begin
assign(f,'scmax.in');
reset(f);
readln(f,n);
for i:=1 to n do
read(f,a[i]);
close(f);
L[n]:=1;
poz[n]:=-1;
max:=L[n];
p:=n;
for i:=n-1 downto 1 do
begin
L[i]:=1;
poz[i]:=-1;
for j:=i+1 to n do
if (a[i]<a[j]) and (L[i]<1+L[j]) then
begin
L[i]:=1+L[j];
poz[i]:=j;
end;
if max<L[i] then begin
max:=L[i];
p:=i;
end;
end;
assign(f,'scmax.out'); rewrite(f);
writeln(f,max);
i:=p;
while i<>-1 do
begin
write(f,a[i],' ');
i:=poz[i];
end;
close(f);
End.