Pagini recente » Cod sursa (job #3230568) | Cod sursa (job #312488) | Cod sursa (job #1778018) | Cod sursa (job #772730) | Cod sursa (job #298909)
Cod sursa(job #298909)
var f,g:text;
a,c,poz,d:array[0..10001] of longint;
i,j,max,k,p,n,w:longint;
begin
assign(f,'scmax.in');reset(f);
assign(g,'scmax.out');rewrite(g);
read(f,n);
c[0]:=-1;
for i:=1 to n do begin
read(f,a[i]);
for j:=k downto 0 do
if a[i]>c[j] then break;
if j=k then begin
inc(k);
c[k]:=a[i];
inc(p);
poz[p]:=k;
if max<poz[p] then max:=poz[p];
end
else begin
inc(j);
c[j]:=a[i];
inc(p);
poz[p]:=j;
if max<poz[p] then max:=poz[p];
end;
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.