Cod sursa(job #1170710)

Utilizator vasica38Vasile Catana vasica38 Data 14 aprilie 2014 12:48:45
Problema Cutii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.49 kb
program p1;
var a,b,c,v,best,v1:array[0..3500] of longint;
    f,g:Text;
    i,n,j,u,t,k,poz,max,ic,sf:longint;
    b1,b2:array[0..1 shl 17 ] of char;

procedure Sort(l, r: longint);
var
  i, j, x, y: longint;
begin
  i := l; j := r; x := c[(l+r) DIV 2];
  repeat
    while c[i] < x do i := i + 1;
    while x < c[j] do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y;
      y:=b[i]; b[i]:=b[j]; b[j]:=y;
      y:=c[i]; c[i]:=c[j]; c[j]:=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;


function cauta(x,x1:longint):longint;
var mijl:longint;
begin
ic:=1;
sf:=max;
while ic<=sf do begin
        mijl:=(ic+sf) div 2;
        if (x<v[mijl])and(x1<v1[mijl]) then sf:=mijl-1
                else ic:=mijl+1;
                end;
cauta:=ic;
end;

begin
assign(f,'cutii.in');reset(F);
assign(g,'cutii.out');rewrite(G);
settextbuf(f,b1);
settextbuf(g,b2);
readln(f,n,t);
for k:=1 to t do begin
        for i:=1 to n do readln(f,a[i],b[i],c[i]);
        sort(1,n);
        for i:=0 to n do begin
                v[i]:=0;
                v1[i]:=0;
                        end;
        max:=0;
        for i:=1 to n do begin
                poz:=cauta(a[i],b[i]);
                v[poz]:=a[i];
                v1[poz]:=b[i];
                if poz>max then max:=poz;
                        end;
        writeln(g,max);
        end;

close(F);
close(G);
 end.