Pagini recente » Cod sursa (job #1005354) | Cod sursa (job #1942325) | Cod sursa (job #420670) | Cod sursa (job #132007) | Cod sursa (job #44475)
Cod sursa(job #44475)
var v,l,p:array[1..5000]of longint;
i,j,n,max,poz:longint;
begin
assign(input,'subsir2.in');reset(input);
assign(output,'subsir2.out');rewrite(output);
readln(n);
for i:=1 to n do
read(v[i]);
l[n]:=1;
p[n]:=n;
for i:=n-1 downto 1 do
begin
l[i]:=1;
p[i]:=i;
for j:=i+1 to n do
if (v[i]<=v[j])and(l[i]<l[j]+1) then
begin
l[i]:=l[j]+1;
p[i]:=j;
end;
end;
max:=1;
for i:=2 to n do
if l[i]>l[max] then
max:=i;
writeln(l[max]);
poz:=max;
for i:=1 to l[max] do
begin
write(poz,' ');
poz:=p[poz];
end;
close(input);close(output);
end.