Pagini recente » Cod sursa (job #2699196) | Cod sursa (job #2586870) | Cod sursa (job #2112939) | Cod sursa (job #2391517) | Cod sursa (job #298941)
Cod sursa(job #298941)
var f,g:text;
a,c,poz,d:array[0..10001] of longint;
i,j,max,k,p,n,w:longint;
procedure insert(x,st,dr:longint);
var m:longint;
begin
m:=(st+dr) div 2;
if st>=dr then begin
if dr=k+1 then begin
inc(k);
c[k]:=x;
inc(p);
poz[p]:=k;
end
else begin
inc(p);
poz[p]:=st+1;
c[st+1]:=x;
end;
end
else
if c[m]<x then insert(x,m+1,dr)
else insert(x,st,m-1);
end;
begin
assign(f,'scmax.in');reset(f);
assign(g,'scmax.out');rewrite(g);
read(f,n);
for i:=1 to n do begin
read(f,a[i]);
insert(a[i],1,k+1);
if poz[p]>max then max:=poz[p];
end;
writeln(g,max);
for i:=p downto 1 do begin
if poz[i]=max then begin
inc(w);
d[w]:=a[i];
dec(max);
end;
if max<=0 then break;
end;
for i:=w downto 1 do write(g,d[i],' ');
close(f);
close(g);
end.