Pagini recente » Cod sursa (job #567621) | Cod sursa (job #2592961) | Cod sursa (job #2866304) | Cod sursa (job #3238449) | Cod sursa (job #559804)
Cod sursa(job #559804)
type vek=array[1..100000]of longint;
var v1,v2,v3:vek;
i,j,n,mx,a,b:longint;
f,g:text;
function max1(i:integer):integer;
var k:integer;
begin
max1:=0;
if i=n then max1:=0
else for k:=i+1 to n do
if (v1[k]>v1[i]) and (v2[k]>max1) then max1:=v2[k];
end;
begin
assign(f,'scmax.in');
reset(f);
readln(f,n);
for i:=1 to n do
read(f,v1[i]);
close(f);
for i:=n downto 1 do
v2[i]:=max1(i)+1;
mx:=v2[1];
a:=1;
for i:=2 to n do
if v2[i]>mx then
begin
mx:=v2[2];
a:=i;
end;
assign(g,'scmax.out');
rewrite(g);
writeln(g,mx);
close(g);
append(g);
v3[1]:=v1[a];
dec(mx);
b:=1;
for i:=a+1 to n do
begin
if (v2[i]=mx) and (mx<>0) and (v1[i]>v3[b]) then
begin
v3[b+1]:=v1[i];
inc(b);
dec(mx);
end;
end;
for i:=1 to b do
write(g,v3[i],' ');
close(g);
end.