Pagini recente » Cod sursa (job #2668815) | Cod sursa (job #2537419) | Cod sursa (job #2895221) | Cod sursa (job #1908310) | Cod sursa (job #719037)
Cod sursa(job #719037)
var i,j,max,n,poz:integer;
t,l:array[1..100000] of longint;
var f:text;
procedure sir;
begin
l[n]:=1;
for i:=n-1 downto 1 do
begin
max:=0;
for j:=i+1 to n do
if (t[i]<t[j]) and (l[j]>max) then
max:=l[j];
l[i]:=max+1;
end;
end;
begin
assign(f,'scmax.in');
reset(f);
readln(f,n);
for i:=1 to n do
read(f,t[i]);
sir;
max:=0;
for i:=1 to n do
if l[i]>=max then begin
max:=l[i];
poz:=i;
end;
assign(f,'scmax.out');
rewrite(f);
writeln(f,max);
write(f,t[poz],' ');
for i:=1 to n do
if (t[i]>t[poz]) and (l[i]=max-1) then
begin
write(f,t[i],' ');
dec(max);
end;
close(f);
readln
end.