Pagini recente » Cod sursa (job #862272) | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #2813623) | Cod sursa (job #742291)
Cod sursa(job #742291)
var a,b:array[1..100000] of longint;
i,n,max,j,k:longint;
BEGIN
assign(input,'scmax.in');
reset(input);
readln(n);
for i:=1 to n do
read(a[i]);
close(input);
b[n]:=1;
for i:=n-1 downto 1 do
begin
max:=0;
for j:=i+1 to n do
if (a[j]>a[i]) then
if b[j]>max then
max:=b[j];
b[i]:=max+1;
End;
max:=0;
for i:=1 to n do
if b[i]>max then
begin
max:=b[i];
k:=i;
end;
assign(output,'scmax.out');
rewrite(output);
writeln(max);
write(a[k], ' ');
max:=max-1;
for i:=k+1 to n do
if a[i]>a[k] then
if b[i]=max then
begin
max:=max-1;
write(a[i],' ');
end;
END.