Cod sursa(job #18141)

Utilizator al3csutzuSirbu Alexandru al3csutzu Data 18 februarie 2007 10:03:09
Problema Amlei Scor 100
Compilator fpc Status done
Runda preONI 2007, Runda 2, Clasa a 9-a si gimnaziu Marime 1.31 kb
program amlei;
var n,u,t,i,k,p:integer;
suma1,suma2:array [1..500] of integer;
f,g:text;
begin
  assign(f,'amlei.in'); assign(g,'amlei.out');
  reset(f); rewrite(g);
  while not(eof(f)) do
    begin
      read (f,n,t,u);
      if (n>0) and (u>0) and (t>0) then
      begin
      k:=0;
      for i:=1 to n*t do
        begin
          read (f,p);
          if i mod n<>1 then suma1[k]:=suma1[k]+p
                        else begin k:=k+1; suma1[k]:=p; end;
        end;
      k:=0;
      for i:=1 to n*u do
        begin
          read (f,p);
          if i mod n<>1 then suma2[k]:=suma2[k]+p
                        else begin k:=k+1; suma2[k]:=p; end;
        end;
        k:=1;
        for i:=1 to t do
        begin
          for p:=1 to u do
            begin
              if suma1[i]=suma2[p] then break;
              if p=u then begin writeln(g,'NU'); k:=0; end;
            end;
        if k=0 then break;
        end;
        if k=1 then
        for i:=1 to u do
        begin
          for p:=1 to t do
            begin
              if suma2[i]=suma1[p] then break;
              if p=t then begin writeln(g,'NU'); k:=0; end;
            end;
          if k=0 then break;
        end;
        if k=1 then writeln(g,'DA');
      end;
    end;
  close(f);
  close(g);
end.