Cod sursa(job #22752)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 27 februarie 2007 12:04:32
Problema Cutii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.64 kb
var f,g:text;
a:array[1..3500,1..3] of integer;
b,c:array[1..3500] of integer;
nr,poz,n,i,j,k,l,t,min: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[1]:=a[1,2];
    c[1]:=a[1,3];
    nr:=1;
    for i:=2 to n do
    begin
    min:=maxint;
        for j:=1 to nr do
                  if (b[j]>a[i,2]) and (c[j]>a[i,3]) then
                                                 if b[j]<min then begin
                                                                  min:=b[j];
                                                                  poz:=j;
                                                                  end;
    if min<>maxint then
    begin
                   b[poz]:=a[i,2];
                   c[poz]:=a[i,3];
                   end
                   else
                   begin
                   nr:=nr+1;
                   b[nr]:=a[i,2];
                   c[nr]:=a[i,3];
                   end;     end;
    writeln(g,nr);
    end;
close(F);
close(G);
end.