Cod sursa(job #676613)

Utilizator andreifirstCioara Andrei Ioan andreifirst Data 9 februarie 2012 13:15:41
Problema Subsir crescator maximal Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.88 kb
var v, p, q:array [1.. 100000] of longint;
    i, j, n, m, ri, t:longint;
    f, g:text;
    r:array [1..100000] of longint;
    buf1, buf2:array [1.. 1 shl 17] of char;
    ok:boolean;

begin
assign (f, 'scmax.in'); settextbuf (f, buf1); reset (f);
assign (g, 'scmax.out'); settextbuf (g, buf2); rewrite (g);

read (f, n); for i := 1 to n do read (f, v[i]);

t:=0;
for i := 1 to n do
  begin
  ok:=true;

  j:=1;
  while (j <= t) and ok do
    begin
    if v[i]<=q[j] then
      begin
      q[j]:=v[i];
      p[i]:=j;
      ok:=false;
      end;
    inc (j)
    end;
  if ok then begin inc (t); q[t]:=v[i]; p[i]:=t; end;

  end;

writeln (g, t);

i:=n;
while t <> 0 do
  begin
  if p[i]=t then
    begin
    inc (ri); r[ri]:=v[i];
    dec (t);
    end;
  dec (i);
  end;


for i := ri downto 1 do write (g, r[i], ' ');

close (f); close (g);
end.