Pagini recente » Cod sursa (job #1588882) | Cod sursa (job #1608683) | Cod sursa (job #2607048) | Cod sursa (job #2924635) | Cod sursa (job #899073)
Cod sursa(job #899073)
program sss;
var f,g:text;
n,i,l,lung:longint;
v,q,x,pastreaza:array[1..100005] of longint;
procedure pune(nr,st,sf:longint);
var mij:longint;
begin
if st=sf then
begin
q[st]:=nr;
x[i]:=st;
end
else
begin
mij:=(st+sf) div 2;
if nr<=q[mij] then
pune(nr,st,mij)
else
pune(nr,mij+1,sf);
end;
end;
begin
assign(f,'scmax.in'); reset(f);
assign(g,'scmax.out'); rewrite(g);
readln(f,n);
for i:=1 to n do
read(f,v[i]);
l:=0;
for i:=1 to n do
begin
if v[i]>q[l] then
begin
l:=l+1;
q[l]:=v[i];
x[i]:=l;
end
else
pune(v[i],1,l);
end;
writeln(g,l);
lung:=l;
for i:=n downto 1 do
begin
if x[i]=l then
begin
pastreaza[l]:=v[i];
l:=l-1;
end;
end;
for i:=1 to lung do
write(g,pastreaza[i],' ');
close(f);
close(g);
end.