Pagini recente » Monitorul de evaluare | Cod sursa (job #2392569) | Cod sursa (job #1748244) | Cod sursa (job #219964) | Cod sursa (job #681145)
Cod sursa(job #681145)
var f,g:text;
a,b,c:array[1..100000] of longint;
n,i,j,e,max,m,p:integer;
ok:boolean;
begin
assign(f,'scmax.in'); reset (f);
assign(g,'scmax.out'); rewrite (g);
readln (f,n);
for i:=1 to n do
read (f,a[i]);
max:=0;
e:=0;
for i:=1 to n do
begin ok:=false;
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.