Pagini recente » Cod sursa (job #535024) | Cod sursa (job #1968400) | Cod sursa (job #501089) | Cod sursa (job #1020342) | Cod sursa (job #757618)
Cod sursa(job #757618)
var f,g:text;
m,n:integer;
a:array[1..16,1..16] of longint;
s,x,y:longint;
i,j:integer;
begin
assign (f,'flip.in');reset(f);
assign (g,'flip.out');rewrite(g);
read (f,n,m);s:=0;
for i:=1 to n do
for j:=1 to m do
read (f,a[i,j]);
for i:=1 to n do begin
x:=0;y:=0;
for j:=1 to m do
if a[i,j]>0 then
x:=x+a[i,j]
else
y:=y+a[i,j];
if x<abs(y) then
for j:=1 to m do
a[i,j]:=-1*a[i,j];
end;
for i:=1 to m do begin
x:=0;
y:=0;
for j:=1 to n do
if a[j,i]>0 then
x:=x+a[j,i]
else
y:=y+a[j,i];
if x>abs(y) then
s:=s+x
else
s:=s+abs(y);
end;
write (g,s);
close(g);
end.