Pagini recente » Cod sursa (job #404529) | Cod sursa (job #2532484) | Cod sursa (job #96217) | Cod sursa (job #2863987) | Cod sursa (job #562415)
Cod sursa(job #562415)
var best,a,poz:array[1..100000] of longint;
max,sol,p,n,i,j:longint;
f1,f2:text;
begin
assign(f1,'scmax.in');
assign(f2,'scmax.out');
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
best[n]:=1;
poz[n]:=-1;
max:=1;
p:=n;
for i:=n-1 downto 1 do
begin
best[i]:=1;
poz[i]:=-1;
for j:=i+1 to n do
if (a[i]<a[j])and(best[i]<best[j]+1) then
begin
best[i]:=best[j]+1;
poz[i]:=j;
if best[i]>max then begin max:=best[i]; p:=i; end;
end;
end;
writeln(f2,max);
i:=p;
while i>-1 do
begin
write(f2,a[i],' ');
i:=poz[i];
end;
close(f2);
end.