Pagini recente » Cod sursa (job #906525) | Cod sursa (job #1508412) | Cod sursa (job #1580437) | Cod sursa (job #935071) | Cod sursa (job #68469)
Cod sursa(job #68469)
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]=1 then y:=i;
b[1]:=y; b[0]:=1; nr:=2;
while y<=n do begin
x:=n;
while (x>y) and(p[x]<>nr) do dec(x);
if y<>x then begin inc(b[0]); b[b[0]]:=x; y:=x-1; end else y:=n;
inc(nr); inc(y);
end;
writeln(g,b[0]);
for i:=1 to b[0]-1 do write(g,b[i],' ');
writeln(g,b[b[0]]);
close(f); close(g);
end.