Pagini recente » Cod sursa (job #2493948) | Cod sursa (job #1319737) | Cod sursa (job #390279) | Cod sursa (job #2592030) | Cod sursa (job #893170)
Cod sursa(job #893170)
var f,g:text;
n,l,i,j,o,min,osz:longint;
k:integer;
c:char;
a:array[1..15,1..1000]of integer;
s,b:array[1..1000]of integer;
r,q:real;
begin
assign(f,'sobo.in');reset(f);
assign(g,'sobo.out');rewrite(g);
readln(f,n,l);
min:=maxint;
for i:=1 to n do begin
for j:=1 to l do begin
read(f,c);
val(c,a[i,j],k);
s[j]:=s[j]+a[i,j];
end;
readln(f);
end;
for j:=1 to l do begin read(f,b[j]); if b[j]<min then min:=b[j]; end;
if n=1 then writeln(g,'0') else
if n=2 then writeln(g,min) else begin
j:=0;
osz:=0;
r:=n/2;
repeat
k:=0;o:=0;
for i:=1 to l do if abs(s[i]-r)<abs(o-r) then begin o:=s[i]; k:=i; end;
j:=j+o;
s[k]:=-maxint;
osz:=osz+b[k];
until j>n;
writeln(g,osz);
end;
{for i:=1 to n do
for j:=1 to n do write(b[j],' '); }
close(f);
close(g);
end.