Pagini recente » Cod sursa (job #1677896) | Cod sursa (job #2679665) | Cod sursa (job #2855003) | Cod sursa (job #411760) | Cod sursa (job #29765)
Cod sursa(job #29765)
var f:text;
i,j,a,b,n,m,x,y,o,p:longint;
v:array[1..16,1..16] of longint;
gasit:boolean;
function sl(x,a:integer):longint;
var i:integer;
k:longint;
begin
k:=0;
for i:=1 to m do
inc(k,v[x,i]*a);
sl:=k;
end;
function sc(x,a:integer):longint;
var i:integer;
k:longint;
begin
k:=0;
for i:=1 to n do
inc(k,v[i,x]*a);
sc:=k;
end;
begin
assign(f,'flip.in');reset(f);
readln(f,n,m);
for i:=1 to n do for j:=1 to m do read(f,v[i,j]);close(f);
gasit:=true;
while gasit do
begin
gasit:=false;
a:=0;b:=0;
for i:=1 to m do
begin
x:=sc(i,1);y:=sc(i,-1);
x:=y-x;
if x>a then begin a:=x;p:=i;end;
end;
for i:=1 to n do
if (sl(i,1)<sl(i,-1))and(sl(i,-1)>b) then b:=sl(i,-1);
if (a>0)or(b>0) then
begin
if a>b then
begin for i:=1 to m do v[i,a]:=v[i,a]*-1;end
else begin for i:=1 to n do v[b,i]:=v[b,i]*-1;end;
gasit:=true;end;
end;
a:=0;
for i:=1 to n do
for j:=1 to m do inc(a,v[i,j]);
writeln(a);
end.