Cod sursa(job #1113181)

Utilizator EuBossuletMuntea Andrei EuBossulet Data 20 februarie 2014 13:37:07
Problema Subsir crescator maximal Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 0.61 kb
Program subsir;
var a,b:array[1..100000] of longint;
    i,j,n,max:longint;
    f,q:text;
begin
assign(f,'scmax.in');
reset(f);
assign(q,'scmax.out');
rewrite(q);
readln(f,n);
max:=0;
for i:=1 to n do read(f,a[i]);
for i:=n downto 1 do
begin
        b[i]:=1;
        j:=i+1;
        while (j<=n) and  (a[i]>=a[j]) do
        begin
        if (a[i]<a[j]) and (b[i]<b[j]+1) then b[i]:=b[j]+1;
        inc(j);
        end;
        b[i]:=b[j]+1;
        if b[i]>max then max:=b[i];
end;
writeln(q,max);
for i:=1 to n do if b[i]=max then begin write(q,a[i],' '); dec(max); end;
close(f);
close(q);
end.