Cod sursa(job #1101384)

Utilizator Vasile_Catananoname Vasile_Catana Data 8 februarie 2014 13:19:40
Problema Subsir crescator maximal Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 1.37 kb
program p1;
var a,b,drum:array[0..100000] of longint;
    f,g:text;
    i,n,j,k,u,aux,max,m,p:longint;
    b1,b2:array[0..1 shl 17 ] of char;
{procedure Sort(l, r: longint);
var
  i, j, x, y: longint;
begin
  i := l; j := r; x := a[(l+r) DIV 2];
  repeat
    while a[i] < x do i := i + 1;
    while x < a[j] do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y; aux:=b[i]; b[i]:=b[j]; b[j]:=aux;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);
end;  }
begin
assign(f,'scmax.in');reset(F);
assign(g,'scmax.out');rewrite(G);
settextbuf(f,b1);
settextbuf(g,b2);
readln(f,n);
for i:=1 to n do
          read(f,a[i]);
b[1]:=1;
for i:=2 to n do begin
        m:=0;
        for j:=1 to i-1 do
                if a[j]<a[i] then
                        if b[j] >m  then begin
                                drum[i]:=j;
                                m:=b[j];
                                   end;
        b[i]:=m+1;
        end;
m:=b[1];
for i:=2 to n do
        if b[i]>m then begin
                m:=b[i];
                p:=i;
                        end;
writeln(g,m);
for i:=1 to m do begin
        b[i]:=a[p];
        p:=drum[p];
                end;
for i:=m downto 1 do write(g,b[i],' ');
close(F);
close(G);
end.

close(F);
close(G);
end.