Cod sursa(job #749229)

Utilizator MaarcellKurt Godel Maarcell Data 16 mai 2012 11:02:41
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.56 kb
var i,j,k,l,m,n,max,max1,p:longint; f1,f2:text; a,b:array[1..100000] of longint;
begin
assign(f1,'scmax.in');
reset(f1);
assign(f2,'scmax.out');
rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
b[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<b[j]) then max:=b[j];
b[i]:=1+max;
if b[i]>max1 then begin max1:=b[i]; p:=i; end;
end;
writeln(f2,max1);
write(f2,a[p],' ');
for i:=p+1 to n do
if (a[p]<a[i]) and (b[i]=max1-1) then begin
write(f2,a[i],' ');
Dec(max1);
end;
close(f1);
close(f2);
end.