Pagini recente » Cod sursa (job #697061) | Cod sursa (job #1339572) | Cod sursa (job #224220) | Cod sursa (job #3173023) | Cod sursa (job #573194)
Cod sursa(job #573194)
program infoarena_flip;
var i,j,k2,m,n,s,smax,j1,x1:longint;
a:array[1..16,1..16] of longint;
begin
assign(input,'flip.in');
reset(input);
read(n);readln(m);
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
close(input);
smax:=0;
j1:=1 shl m;
j1:=j1-1;
for k2:=0 to j1 do
begin
s:=0;
for i:=1 to n do
begin
x1:=0;
for j:=1 to m do
if k2 and (1 shl (j-1))>0 then x1:=x1-a[i,j]
else x1:=x1+a[i,j];
if x1<0 then s:=s-x1
else s:=s+x1;
end;
if s>smax then smax:=s;
end;
assign(output,'flip.out');
rewrite(output);
writeln(smax);
close(output);
end.