Pagini recente » Cod sursa (job #168321) | Cod sursa (job #1779533) | Cod sursa (job #867533) | Cod sursa (job #1350963) | Cod sursa (job #279814)
Cod sursa(job #279814)
program cel_mai_lung_subsir_crescator;
var f,g:text;
a:array[1..100000] of longint;
d,suc:array[1..100000] of longint;
n,max,pr:longint;
procedure citire;
var i:longint;
begin
readln(f,n);
for i:=1 to n do read(f,a[i]);
end;
procedure detmax;
var i,j,mmax,succ:integer;
begin
d[n]:=1;
suc[n]:=0;
for i:=n-1 downto 1 do begin
mmax:=0;
for j:=i+1 to n do
if a[i]<a[j] then
if d[j]>mmax then begin
mmax:=d[j];
succ:=j;
end;
d[i]:=mmax+1;
if d[i]>max then begin
max:=d[i];
pr:=i;
end;
if mmax>0 then suc[i]:=succ else suc[i]:=0;
end;
end;
procedure scriere;
var i,x:longint;
begin
writeln(g,max);
x:=pr;
for i:=1 to max do begin
write(g,a[x],' ');
x:=suc[x];
end;
end;
begin
assign(f,'scmax.in');
assign(g,'scmax.out');
reset(f);
rewrite(g);
citire;
detmax;
scriere;
close(f);
close(g);
end.