Pagini recente » Cod sursa (job #1616332) | Cod sursa (job #1766451) | Cod sursa (job #2251938) | Cod sursa (job #2044810) | Cod sursa (job #405107)
Cod sursa(job #405107)
const infile='scmax.in';
outfile='scmax.out';
maxn=100001;
var a,m,p,b:array[0..maxn]of longint;
n,lg:longint;
procedure citire;
var i:longint;
f:text;
begin
assign(f,infile); reset(f);
readln(f,n); for i:=1 to n do read(f,a[i]);
close(f);
end;
procedure solve;
var i,k,j,st:longint;
begin
lg:=0; k:=1;
for i:=1 to n do begin
while(k shl 1<=lg)do k:=k shl 1;
j:=0; st:=k;
while(st>0)do begin
if(j+st<=lg)and(a[m[j+st]]<a[i])then inc(j,st);
st:=st shr 1;
end;
p[i]:=m[j]; b[i]:=b[m[j]]+1;
if(j=lg)or(a[i]<a[m[j+1]])then begin
m[j+1]:=i;
if(lg<j+1)then lg:=j+1;
end;
end;
end;
procedure recons(x:longint);
begin
if(p[x]<>0)then recons(p[x]);
write(a[x],' ');
end;
procedure afisare;
var i,max,poz:longint;
begin
writeln(lg);
max:=b[1];
for i:=2 to n do if(max<b[i])then begin max:=b[i]; poz:=i; end;
recons(poz);
end;
Begin
citire; solve;
assign(output,outfile); rewrite(output);
afisare;
close(output);
end.