Pagini recente » Cod sursa (job #2729848) | Cod sursa (job #2503987) | Cod sursa (job #704364) | Cod sursa (job #1651485) | Cod sursa (job #46692)
Cod sursa(job #46692)
type bi=0..1000;
bec=record c,t,nr:bi;
a:array[bi] of 0..100;
end;
var f,g:text;
n,m,s:longint;
x:array[0..100] of bec;
y:array[bi]of 0..1;
procedure cit;
var i,j:bi;
begin
assign(f,'aprindere.in');reset(f);
assign(g,'aprindere.out');rewrite(g);
readln(f,n,m);
for i:=0 to n-1 do read(f,y[i]);
readln(f);
for i:=1 to m do begin
read(f,x[i].c, x[i].t, x[i].nr);
for j:=1 to x[i].nr do
read(f,x[i].a[j]);
readln(f)
end;
end;
function caut:shortint;
var i:bi;
gasit:boolean;
begin
caut:=-1;
i:=0;
gasit:=false;
while (i<n)and not gasit do begin
if y[i]=0 then begin caut:=i;
gasit:=true
end;
inc(i);
end;
end;
procedure munca;
var j,i:bi;k:shortint;
begin
k:=caut;
while k<>-1 do begin
for i:=1 to m do
if x[i].c=k then begin
for j:=1 to x[i].nr do
if y[x[i].a[j]]=0 then y[x[i].a[j]]:=1
else y[x[i].a[j]]:=0;
s:=s+x[i].t;
end;
k:=caut;
end;
end;
begin {pp}
cit;
munca;
writeln(g,s);
close(g);
end.