Pagini recente » Cod sursa (job #2845143) | Cod sursa (job #2658210) | Cod sursa (job #123447) | Cod sursa (job #3182218) | Cod sursa (job #361601)
Cod sursa(job #361601)
var a,best,prev:array[0..100005] of longint;
j,i,n,max:longint;
function caut(st,dr:longint):longint;
var mij:longint;
begin
if st=dr then
if a[best[st]]<a[i] then caut:=st
else caut:=st-1
else begin
mij:=(st+dr) shr 1;
if a[best[mij]]<a[i] then caut:=caut(mij+1,dr)
else caut:=caut(st,mij);
end;
end;
procedure afiseaza(i:longint);
begin
if prev[i]<>0 then afiseaza(prev[i]);
write(a[i],' ');
end;
begin
assign(input,'scmax.in');
reset(input);
assign(output,'scmax.out');
rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
best[0]:=0;
max:=0;
for i:=2 to n do begin
j:=caut(0,max);
prev[i]:=best[j];
if (j=max) or (a[i]<a[best[j+1]]) then begin
best[j+1]:=i;
if max<j+1 then max:=j+1;
end;
end;
writeln(max);
i:=best[max];
afiseaza(i);
close(input);
close(output);
end.