Pagini recente » Cod sursa (job #1304661) | Cod sursa (job #145954) | Cod sursa (job #89257) | Cod sursa (job #1788118) | Cod sursa (job #32408)
Cod sursa(job #32408)
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.