Pagini recente » Cod sursa (job #1645297) | Cod sursa (job #3177784) | Cod sursa (job #3281626) | Cod sursa (job #556028) | Cod sursa (job #700946)
Cod sursa(job #700946)
var f,g:text;
a,b,c:array[0..100000] of int64;
i,j,e,max,p:longint;
m,n:longint;
ok:boolean;
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);
readln (f,n);
max:=0;
e:=0;
for i:=1 to n do
begin read (f,a[i]);
ok:=false;
if a[i]>b[m div 2] then j:=m div 2
else if a[i]=b[m div 2] then j:=m div 2
else j:=1;
while (j<=m) and (ok=false) do
begin if b[j]>=a[i] then begin b[j]:=a[i]; ok:=true; p:=j; end;
j:=j+1;
end;
if ok=false then begin m:=m+1; b[m]:=a[i]; p:=m; end;
c[i]:=p;
if c[i]>max then begin max:=c[i]; e:=i; end;
end;
writeln (g,max);
i:=n;
m:=0;
while (i>0) and (max>=1) do
begin if c[i]=max then begin m:=m+1;
b[m]:=a[i];
max:=max-1;
end;
i:=i-1;
end;
for i:=m downto 1 do
write (g,b[i],' ');
close (f);
close (g);
end.