Pagini recente » Cod sursa (job #2619910) | Cod sursa (job #2367479) | Cod sursa (job #2082013) | Cod sursa (job #1813) | Cod sursa (job #399195)
Cod sursa(job #399195)
var n,i,j,max,x,y,k:longint;
lung,a,poz:array[1..100000]of longint;
f:text;
procedure mac1;
begin
assign(f,'scmax.in');
reset(f);
readln(f,n);
for i:=1 to n do read(f,a[i]);
close(f);
y:=0;
for i:=1 to n do
begin
max:=0;
for j:=1 to i-1 do
if(a[i]>a[j])and(max<lung[j])then max:=lung[j];
lung[i]:=max+1;
if lung[i]>y then begin y:=lung[i]; k:=i; end;
end;
x:=y;
for i:=k downto 1 do
if lung[i]=x then begin poz[i]:=1;x:=x-1; end;
assign(f,'scmax.out');
rewrite(f);
writeln(f,y);
for i:=1 to k do if(poz[i]=1)then write(f,a[i],' ');
close(f);
end;
begin
mac1;
end.