Pagini recente » Cod sursa (job #1496607) | Cod sursa (job #1203872) | Cod sursa (job #749399) | Cod sursa (job #1093038) | Cod sursa (job #292326)
Cod sursa(job #292326)
{scmax}
var v:array[1..100000] of longint;
l:array[1..100000] of longint;
f,g:text;
max,n,inceput:longint;
procedure citire;
var i:longint;
begin
assign(f,'scmax.in'); reset(f);
readln(f,n);
for i:=1 to n do read(f,v[i]);
close(f);
end;
procedure subsir;
var i,j:longint;
begin
l[n]:=1;
for i:=n-1 downto 1 do
begin
max:=0;
for j:=i+1 to n do
if (l[j]>max) and (v[j]>v[i]) then max:=l[j];
l[i]:=max+1;
end;
max:=l[1];
inceput:=1;
for i:=2 to n do
if l[i]>max then
begin
max:=l[i];
inceput:=i;
end;
end;
procedure afisare;
var i,j:longint;
begin
write(g,v[inceput],' ');
j:=inceput;
for i:=inceput+1 to n do
if (l[i]=max-1) and (v[i]>v[j]) then
begin
write(g,v[i],' ');
j:=i;
dec(max);
end;
close(g);
end;
begin
assign(g,'scmax.out'); rewrite(g);
citire;
subsir;
writeln(g,max);
afisare;
end.