Pagini recente » Cod sursa (job #1139396) | Cod sursa (job #3287238) | Cod sursa (job #2911933) | Cod sursa (job #2487108) | Cod sursa (job #482580)
Cod sursa(job #482580)
program scmax;
var n,i,max,poz,nr:longint;
v,l,best,tata:array[0..100000]of longint;
procedure afis(x:longint);
begin
if tata[x]>0 then afis(tata[x]);
write(v[x],' ');
end;
function caut(x:longint):longint;
var p,u,m:longint;
ok:boolean;
begin
p:=0; u:=nr; m:=(p+u)shr 1; ok:=false;
while p<=u do
if (v[l[m]]<x) and (v[l[m+1]]>=x) then begin
caut:=m;
ok:=true;
break;
end
else if v[l[m+1]]<x then begin
p:=m+1;
m:=(p+u)shr 1;
end
else begin
u:=m-1;
m:=(p+u) shr 1;
end;
if not ok then caut:=nr;
end;
begin
assign(input,'scmax.in');
reset(input);
read(n);
for i:=1 to n do read(v[i]);
nr:=1;
best[1]:=1;
l[1]:=1; l[0]:=0;
for i:=2 to n do begin
poz:=caut(v[i]);
tata[i]:=l[poz];
best[i]:=poz+1;
l[poz+1]:=i;
if nr<poz+1 then nr:=poz+1;
end;
max:=0; poz:=0;
for i:=1 to n do
if max<best[i] then begin
max:=best[i];
poz:=i;
end;
assign(output,'scmax.out');
rewrite(output);
writeln(max);
afis(poz);
close(output);
end.