Cod sursa(job #22722)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 27 februarie 2007 10:24:31
Problema Cutii Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.17 kb
var f,g:text;
a:array[1..3500,1..3] of integer;
b:array[1..3500] of integer;
n,i,j,k,l,t,max:longint;
procedure Sort(l, r: Integer);
var
  i, j, x, y: integer;
begin
  i := l; j := r; x := a[(l+r) DIV 2,1];
  repeat
    while a[i,1] < x do i := i + 1;
    while x < a[j,1] do j := j - 1;
    if i <= j then
    begin
      y := a[i,1]; a[i,1] := a[j,1]; a[j,1] := y;
      y := a[i,2]; a[i,2] := a[j,2]; a[j,2] := y;
      y := a[i,3]; a[i,3] := a[j,3]; a[j,3] := y;
      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,'cutii.in');
assign(g,'cutii.out');
reset(F);
rewrite(G);
readln(f,n,t);
for k:=1 to t do
begin
    for i:=1 to n do
        for j:=1 to 3 do
            read(f,a[i,j]);
    sort(1,n);
    b[n]:=1;
    for i:=n-1 downto 1 do
    begin
    max:=0;
              for j:=i+1 to n do
                  if (a[j,2]>a[i,2]) and (a[j,3]>a[i,3]) then
                                     if b[j]>max then max:=b[j];
    b[i]:=1+max;
    end;
    max:=0;
    for i:=1 to n do
    if b[i]>max then max:=b[i];
    writeln(g,max);
    end;
close(F);
close(G);
end.