Pagini recente » Cod sursa (job #2457417) | Cod sursa (job #889541) | Cod sursa (job #3197396) | Cod sursa (job #1727992) | Cod sursa (job #49618)
Cod sursa(job #49618)
var a:array[1..17,0..17] of longint;
f:text;
lin,col,i,j,n,m:integer;
x,ct,summ,summax,sumlin:longint;
begin
assign(f,'flip.in');
reset(f);
read(f,n,m);
for i:=1 to n do
for j:=0 to m-1 do begin
read(f,x);
if n<m then
a[j,i]:=x
else
a[i,j]:=x;
end;
close(f);
if n<m then begin
x:=n;
n:=m;
m:=x;
end;
summax:=-2000000;
for ct:=0 to 1 shl m -1 do begin
summ:=0;
for lin:=1 to n do begin
sumlin:=0;
for col:=0 to m-1 do
if (ct shr col) and 1 = 0 then sumlin:=sumlin+a[lin,col]
else sumlin:=sumlin-a[lin,col];
if sumlin>0 then summ:=summ+sumlin
else summ:=summ-sumlin;
end;
if summ>summax then summax:=summ;
end;
assign(f,'flip.out');
rewrite(f);
write(f,summax);
close(f);
end.