Pagini recente » Cod sursa (job #2120394) | Cod sursa (job #2115834) | Cod sursa (job #1843608) | Cod sursa (job #210793) | Cod sursa (job #298904)
Cod sursa(job #298904)
var f,g:text;
a,c,poz:array[0..10001] of longint;
i,j,max,k,p,n: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
write(g,a[i],' ');
dec(max);
end;
if max<=0 then break;
end;
close(f);
close(g);
end.