Cod sursa(job #670288)

Utilizator DarkWishMasterCebotari Vlad DarkWishMaster Data 28 ianuarie 2012 20:13:57
Problema Cutii Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.19 kb
Program Cutii; Uses Crt;
const nmax=3500;
type Cutie=record
            x,y,z:integer;
           end;
     Cset=array[1..nmax] of Cutie;
var N:integer; a:Cset;
    T:byte;
Function CheckRez:integer;
var L:array[1..nmax] of integer;
    k,i,max,max2:integer;
begin
max2:=0;
l[n]:=1;
for k:=n-1 downto 1 do
 begin
   max:=0;
    for i:=k+1 to n do
      if (a[i].x>a[k].x) and (a[i].y>a[k].y)
        and (a[i].z>a[k].z) and (l[i]>max)
     then max:=l[i];
   l[k]:=1+max;
   if l[k]>max2 then max2:=l[k];
 end;
CheckRez:=max2;
end; {CheckRez}

procedure Citire;
var F,G:text; ti:byte;
    i,j:integer; key:Cutie;
begin
 assign(F, 'cutii.in');
 assign(G, 'cutii.out');
 rewrite(G);
 reset(F);
 readln(F, N, T);
 for ti:=1 to T do
  begin
    for i:=1 to N do
      begin
        read(F, a[i].x, a[i].y, a[i].z); {Citim cutia i}
        key:=a[i];
        j:=i-1;                       {sortam prin insertie}
        while (j>0) and (key.x<a[j].x) do
           begin
             a[j+1]:=a[j];
             j:=j-1;
           end;
         a[j+1]:=key;
      end;    {sortat}
     writeln(G, CheckRez);
  end;
close(F);
close(G);
end; {Citire}
Begin
Citire;
end.