Cod sursa(job #32408)

Utilizator floringh06Florin Ghesu floringh06 Data 17 martie 2007 20:24:25
Problema Aprindere Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.83 kb
type matr = array[0..1001,-1..101] of integer;
     vect = array[0..1001] of integer;

var fi,fo:text;
    i,j,n,m:integer;
    c,tc,nrc,costf:longint;
    a,cost:vect;
    mat:matr;

begin
 assign(fi,'aprindere.in'); reset(fi);
 assign(fo,'aprindere.out'); rewrite(fo);
 readln(fi,n,m);
 for i:=0 to n-1 do
  read(fi,a[i]);
 for i:=1 to m do
  begin
   read(fi,c,tc,nrc);
   mat[c,0]:=1;
   mat[c,-1]:=nrc;
   cost[c]:=tc;
   for j:=1 to nrc do
    read(fi,mat[c,j]);
   readln(fi);
  end;
 for i:=0 to n-1 do
  if a[i]=0 then
   begin
    {if mat[i,0]=0 then
     begin
      write(fo,0);
      close(fo);
      halt;
     end;}
    inc(costf,cost[i]);
    for j:=1 to mat[i,-1] do
     if a[mat[i,j]]=1 then a[mat[i,j]]:=0
      else a[mat[i,j]]:=1;
   end;
writeln(fo,costf);
close(fi);
close(fo);
end.