Pagini recente » Cod sursa (job #2932934) | Cod sursa (job #1703204) | Cod sursa (job #2621902) | Cod sursa (job #3181510) | Cod sursa (job #680651)
Cod sursa(job #680651)
var f,g:text;
n,i,max,j,poz:longint;
a,lung:array[0..100000]of longint;
buf1,buf2:array[1.. 1 shl 17]of char;
begin
assign(f,'scmax.in'); settextbuf(f,buf1); reset(f);
assign(g,'scmax.out'); settextbuf(g,buf2); rewrite(g);
read(f,n);
for i:=0 to n-1 do
read(f,a[i]);
lung[n-1]:=1;
for i:=n-2 downto 0 do
begin
max:=0;
for j:=i+1 to n-1 do
if a[i]<a[j] then if max<lung[j] then max:=lung[j];
lung[i]:=max+1;
end;
max:=lung[0];
poz:=0;
for i:=1 to n-1 do
if max<lung[i] then begin max:=lung[i]; poz:=i;end;
writeln(g,max);
write(g,a[poz],' ');max:=max-1;
for i:=poz+1 to n-1 do
if (lung[i]=max)and(a[i]>poz) then begin
write(g,a[i],' ');
poz:=i;
max:=max-1;
end;
close(f);
close(g);
end.