Pagini recente » Istoria paginii runda/cocalari_danseaza_2014 | Arhiva de probleme | Cod sursa (job #1177918) | Cod sursa (job #854789) | Cod sursa (job #558775)
Cod sursa(job #558775)
type vek=array[1..100000] of longint;
var v,x:vek; f:text; n,i,j,k,max,xx: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; xx:=0;
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;
if x[i]>xx then begin xx:=x[i]; k:=i; end;
end;
{ max:=0;
for i:=1 to n do
if x[i]>max then begin max:=x[i]; k:=i; end; }
max:=xx;
assign(f,'scmax.out');
rewrite(f);
writeln(f,max);
write(f,v[k],' ');
maxx(k);
close(f);
end.