Pagini recente » Cod sursa (job #2880051) | Cod sursa (job #362001) | Cod sursa (job #2025822) | Cod sursa (job #1834842) | Cod sursa (job #742778)
Cod sursa(job #742778)
program subsir;
var n,i,j,max,k:longint;
a,next,best:array[1..100000] of longint;
b1:array[1..1 shl 17] of char;
begin
assign(input,'scmax.in'); settextbuf(input,b1); reset(input);
assign(output,'scmax.out'); rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
close(input);
for i:=n downto 1 do begin
max:=0; k:=i;
for j:=i+1 to n do
if (a[j]>a[i])and(best[j]>max) then begin
max:=best[j];
k:=j;
end;
best[i]:=max+1;
next[i]:=k;
end;
max:=best[1]; k:=1;
for i:=2 to n do
if best[i]>max then begin
k:=i;
max:=best[i];
end;
i:=k;
writeln(max);
while next[i]<>i do begin
write(a[i],' ');
i:=next[i];
end;
write(a[i]);
close(output);
end.