Pagini recente » Arbori Indexati Binar | Cod sursa (job #2023497) | Statistici Matei Ionita (Nemultumitu) | Monitorul de evaluare | Cod sursa (job #558769)
Cod sursa(job #558769)
type vek=array[1..100000] of longint;
var v,x:vek; f:text; n,i,j,k,max:longint;
procedure maxx(a:longint);
var i:longint;t:boolean;
begin
t:=false; i:=a-1;
while (i<n)and not t do begin
inc(i);
if (x[i]=x[a]-1)and(v[i]>v[a]) then begin t:=true;
write(f,v[i],' ');
if x[i]>1 then
maxx(i);
end;
end;
end;
begin
assign(f,'scmax.in');
reset(f);
readln(f,n);
for i:=1 to n do
read(f,v[i]);
close(f);
x[n]:=1;
for i:=n-1 downto 1 do begin
max:=x[i];
for j:=i+1 to n do
if (x[j]>max)and(v[j]>v[i]) then max:=x[j];
x[i]:=max+1; end;
max:=0;
for i:=1 to n do
if x[i]>max then begin max:=x[i]; k:=i; end;
assign(f,'scmax.out');
rewrite(f);
writeln(f,max);
write(f,v[k],' ');
maxx(k);
close(f);
end.