Cod sursa(job #1568242)

Utilizator EusebiuSebyTolomeiu Eusebiu EusebiuSeby Data 13 ianuarie 2016 23:45:06
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.92 kb
program nume;
var n,i,max,k,poz:integer;
    x,l:array[1..100000]of qword;
    f,g:text;
begin
    assign(f,'scmax.in');
    reset(f);
    assign(g,'scmax.out');
    rewrite(g);
    readln(f,n);
    for i:=1 to n do
        read(f,x[i]);
     l[n]:=1;
    for i:=n-1 downto 1 do
       begin
           max:=0;
           for k:=i+1 to n do
              if (x[i]<x[k])and(l[k]>max)then
                           max:=l[k];
              l[i]:=1+max;
       end;
       max:=0;
       for i:=1 to n do
         if l[i]>max then
           begin
               max:=l[i];
               poz:=i;
           end;
           writeln(g,max);
           write(g,x[poz],' ');
         for i:=poz+1 to n do
           if (x[poz]<x[i])and(l[i]=max-1)then
             begin
                  write(g,x[i],' ');
                  poz:=i;
                  max:=max-1;
             end;
close(f);
close(g);
end.