Pagini recente » Cod sursa (job #902323) | Cod sursa (job #1984138) | Cod sursa (job #2421834) | Cod sursa (job #2421902) | Cod sursa (job #68457)
Cod sursa(job #68457)
program subsir_crescator_de_lungime_maxima;
const max=200000000;
var a,p,q,b:array[0..6005] of longint;
f,g:text;
i,j,n,nr,y,x,c:longint;
function cauta(x:longint):longint;
var m,st,dr:integer; ok:boolean;
begin
ok:=false; st:=1; dr:=q[0];
while (st<=dr) and not ok do begin
m:=(st+dr)div 2;
if q[m]=x then ok:=true else
if x<q[m] then dr:=m-1
else st:=m+1;
end;
cauta:=m;
while (q[m]<x) and(m<=q[0]) do inc(m);
cauta:=m;
end;
begin
assign(f,'subsir2.in'); reset(f);
assign(g,'subsir2.out'); rewrite(g);
readln(f,n);
for i:=1 to n do read(f,a[i]);
fillchar(q,sizeof(q),0);
fillchar(p,sizeof(p),0);
q[1]:=max; q[0]:=1;
for i:=1 to n do begin
c:=cauta(a[i]);
if c>q[0] then begin inc(q[0]); q[q[0]]:=a[i]; p[i]:=q[0]; end
else begin p[i]:=c; q[c]:=a[i]; end;
end;
i:=n; nr:=q[0];
for i:=1 to n do if p[i]=nr then y:=i;
dec(nr); x:=a[y];
b[1]:=y; b[0]:=1;
while nr<>0 do begin
while (a[y]>x) or(p[y]<>nr) do dec(y);
inc(b[0]); b[b[0]]:=y;
x:=a[y]; dec(nr);
end;
writeln(g,q[0]);
for i:=b[0] downto 2 do write(g,b[i],' ');
writeln(g,b[1]);
close(f); close(g);
end.