Cod sursa(job #35031)

Utilizator CezarMocanCezar Mocan CezarMocan Data 21 martie 2007 19:07:43
Problema Cutii Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.57 kb
type cutie=record
                x,y,z:longint;
                end;
var v:array[1..3502]of cutie;
    x,zero:array[1..3502]of integer;
    t,i,j,k,n,max:longint;
    aux:cutie;

procedure qSort(l, r: Integer);
var
  i, j, x: integer;
  y:cutie;
begin
  i := l; j := r; x := v[(l+r) DIV 2].x;
  repeat
    while v[i].x < x do i := i + 1;
    while x < v[j].x do j := j - 1;
    if i <= j then
    begin
      y := v[i]; v[i] := v[j]; v[j] := y;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then qSort(l, j);
  if i < r then qSort(i, r);
end;


begin
assign(input,'cutii.in');reset(input);
assign(output,'cutii.out');rewrite(output);
readln(n,t);
for k:=1 to t do
        begin
        for i:=1 to n do
                readln(v[i].x,v[i].y,v[i].z);
        qsort(1,n);
        x:=zero;
        x[n]:=1;
        max:=1;
        for i:=n-1 downto 1 do
                begin
                x[i]:=1;
                for j:=i+1 to n do
                        if (v[i].x<v[j].x)and(v[i].y<v[j].y)and(v[i].z<v[j].z)then
                                begin
                                if x[i]>max then
                                        begin
                                        max:=x[i];
                                        break;
                                        end;

                                if x[i]<x[j]+1
                                        then x[i]:=x[j]+1;
                                end;
                   end;
        writeln(max);
        end;
close(input);close(output);
end.