Pagini recente » Cod sursa (job #2705049) | Cod sursa (job #3258173) | Cod sursa (job #894373) | Cod sursa (job #2896224) | Cod sursa (job #1205347)
var a, d: array[1..100000] of longint;
n, i, k, j, max : longint;
buf1 : array[1..1 shl 17] of char;
begin
Assign(input,'scmax.in');
reset(input);
settextbuf(input, buf1);
readln(n);
For i:=1 to n do
Read(a[i]);
Close(input);
d[n]:=1;
For i:=n-1 downto 1 do
begin max:=0;
For j:=i+1 to n do
if (a[i]<a[j]) and (max<d[j]) then
max:=d[j];
D[i]:=max+1;
end;
Assign(output,'scmax.out');
rewrite(output);
max:=0;
for i:=1 to n do
if d[i]>max then
begin
max:=d[i];
k:=i;
end;
writeln(d[k]);
j:=d[k];
write(a[k],' ');
For i:=k+1 to n do
begin
if d[i]+1=j then
begin
write(a[i],' ');
j:=d[i];
end;
end;
Close(output);
end.