Pagini recente » Cod sursa (job #2347277) | Cod sursa (job #453292) | Cod sursa (job #2606632) | Cod sursa (job #2282635) | Cod sursa (job #830593)
Cod sursa(job #830593)
CONST FISIER:string='scmax';
var fi,fo:text;
lungime,urmator,v:array[1..1000] of longint;
i,ii,lung,max,max_p:longint;
begin
assign(fi,FISIER+'.in');reset(fi);
read(fi,lung);
for i:=1 to lung do
begin
read(fi,v[i]);
urmator[i]:=-1;
lungime[i]:=1;
end;
close(fi); max:=-1;
for i:=lung-1 downto 1 do
begin
for ii:=i+1 to lung do
begin
if v[i]<v[ii] then
if lungime[ii]>=lungime[i] then
begin
lungime[i]:=1+lungime[ii];
urmator[i]:=ii;
end;
end;
if lungime[i]>max then
begin
max:=lungime[i];
max_p:=i;
end;
end;
assign(fo,FISIER+'.out'); rewrite(fo);
writeln(fo,max);
while max_p<>-1 do
begin
write(fo,v[max_p],' ');
max_p:=urmator[max_p];
end;
close(fo);
end.