Pagini recente » Cod sursa (job #622463) | Cod sursa (job #2923499) | Cod sursa (job #323258) | Cod sursa (job #2509511) | Cod sursa (job #32393)
Cod sursa(job #32393)
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:integer;
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:=0 to m-1 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]);
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.