Pagini recente » Cod sursa (job #1472059) | Cod sursa (job #1371681) | Cod sursa (job #139091) | Cod sursa (job #262795) | Cod sursa (job #699147)
Cod sursa(job #699147)
program scm;
var l,v,pre:array[1..100001] of longint;
fi,fo:text;
n,i,max,mx,pmax:longint;
procedure drum(nod:integer);
begin
repeat
write(fo,v[nod],' ');
nod:=pre[nod];
until pre[nod]=0;
write(fo,v[nod]);
end;
procedure scm;
var i,j:longint;
begin
l[n]:=1;
max:=0;
for i:=n-1 downto 1 do
begin
mx:=0;
for j:=i+1 to n do
if v[j]>v[i] then
if l[j]>mx then
begin
mx:=l[j];
pre[i]:=j;
end;
l[i]:=mx+1;
if l[i]>max then
begin
max:=l[i];
pmax:=i;
end;
end;
writeln(fo,max);
drum(pmax);
end;
begin
assign(fi,'scmax.in'); reset(fi);
assign(Fo,'scmax.out'); rewrite(Fo);
readln(Fi,n);
for i:=1 to n do
read(fi,v[i]);
scm;
close(Fi); close(Fo);
end.