Cod sursa(job #46692)

Utilizator reginaRegina M. regina Data 2 aprilie 2007 21:13:04
Problema Aprindere Scor 25
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.22 kb
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.