Cod sursa(job #28501)

Utilizator maria_pparcalabescu maria daniela maria_p Data 7 martie 2007 21:45:50
Problema Aprindere Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.98 kb
var f,g:text;
    b:array[0..1010,0..1010]of longint;
    a,t,c,x:array[0..1010]of longint;
    i,nr,j,aux,timp,m,n:longint;
    ok:boolean;
begin
assign(f,'aprindere.in');reset(f);
assign(g,'aprindere.out');rewrite(g);
readln(f,n,m);
dec(n);dec(m);
for i:=0 to n do
    read(f,x[i]);
readln(f);
for i:=0 to m do
    begin
    read(f,a[i],t[i],b[i,0]);
    for j:=1 to b[i,0] do
        begin
        read(f,b[i,j]);
        if x[b[i,j]]=0 then inc(b[i,n+1]);
        end;
    readln(f);
    end;
for i:=0 to m do
    c[i]:=i;
for i:=0 to m-1 do
    for j:=i+1 to m do
        if t[c[i]]>t[c[j]] then begin
                                aux:=c[i];
                                c[i]:=c[j];
                                c[j]:=aux;
                                end
    else if(t[c[i]]=t[c[j]])and(b[i,0]<b[j,0])then begin
                                                       aux:=c[i];
                                                       c[i]:=c[j];
                                                       c[j]:=aux;
                                                       end
        else if(t[c[i]]=t[c[j]])and(b[i,0]=b[j,0])and(b[i,n+1]<b[j,n+1])
                                                        then begin
                                                             aux:=c[i];
                                                             c[i]:=c[j];
                                                             c[j]:=aux;
                                                             end;
timp:=0;
for i:=0 to n do
    if x[i]=1 then inc(nr);
i:=0;
while nr<n do
    begin
    for j:=1 to b[c[i],0] do
        if x[b[c[i],j]]=0 then begin
                               x[b[c[i],j]]:=1;
                               inc(nr);
                               end
        else begin
             x[b[c[i],j]]:=0;
             dec(nr);
             end;
    timp:=timp+t[c[i]];
    inc(i);
    end;
writeln(g,timp);
close(f);
close(g);
end.