Pagini recente » Cod sursa (job #934914) | Cod sursa (job #296265) | Cod sursa (job #448565) | Cod sursa (job #2747863) | Cod sursa (job #562417)
Cod sursa(job #562417)
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>0 do
begin
write(f2,a[i],' ');
i:=poz[i];
end;
close(f2);
end.