Cod sursa(job #804951)

Utilizator tibi2012Galatanu Tiberiu tibi2012 Data 30 octombrie 2012 19:08:26
Problema Cutii Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.2 kb
type dimens=record
  x,y,z:integer;
end;

var n,t,i,j,max,p,m,s,q,posmax:integer;
    a:array[1..3500] of dimens;
    b,maxval:array[1..3500] of integer;
    b1,b2:array [1..1 shl 12] of char;
    f,g:text;
begin
  assign(f,'cutii.in');
  assign(g,'cutii.out');
  settextbuf(f,b1);
  settextbuf(g,b2);
  reset(f);
  rewrite(g);
  readln(f,n,t);
  for m:=1 to t do
    begin
      q:=0;
      for i:=1 to n do
        begin
          read(f,s);
          a[s].x:=s;
          if s>q then
            q:=s;
          readln(f,a[s].y,a[s].z);
        end;
      b[q]:=1;
      max:=0;
      maxval[q]:=1;
      for i:=q-1 downto 1 do
        begin
          for j:=i+1 to q do
            begin
              if maxval[j]<b[i] then
                break;
              if (a[j].y>a[i].y) and (a[j].z>a[i].z) and (b[j]>b[i]) then
                b[i]:=b[j];
            end;
          inc(b[i]);
          if b[i]>max then
            max:=b[i];
          if maxval[i+1]>b[i] then
            maxval[i]:=maxval[i+1]
          else
            maxval[i]:=b[i];
        end;
      writeln(g,max);
      for i:=1 to q-1 do
        b[i]:=0;
    end;
  close(f);
  close(g);
end.