Pagini recente » Cod sursa (job #1109734) | Cod sursa (job #2602800) | Cod sursa (job #2980993) | Cod sursa (job #2620663) | Cod sursa (job #743621)
Cod sursa(job #743621)
var a,b:array[1..100000] of longint;
i,n,max,j,k:longint;
b1,b2:array[1..1shl 17] of char;
BEGIN
assign(input,'scmax.in');
settextbuf(input,b1);
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');
settextbuf(output,b2);
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.