Pagini recente » Cod sursa (job #3184989) | Cod sursa (job #3244247) | Cod sursa (job #1539708) | Cod sursa (job #105532) | Cod sursa (job #214890)
Cod sursa(job #214890)
program flip;
var n, m, i, j, s, st:longint;
f, g:text;
a, x:array[1..16,1..16] of longint;
gasit:boolean;
begin
assign(f,'flip.in'); reset(f);
assign(g,'flip.out'); rewrite(g);
readln(f, n, m);
gasit:=true;
while gasit do
begin
gasit:=false;
for i:=1 to n do
begin
s:=0;
for j:=1 to m do
begin
read(f,a[i,j]);
s:=s+a[i,j];
st:=st+a[i,j];
end;
if s<0 then
begin
gasit:=true;
{ for j:=1 to m do
begin
if x[i,j]<>1 then
a[i,j]:=0-a[i,j];
x[i,j]:=1;
end;}
st:=st+2*(0-s);
end;
end;
for j:=1 to m do
begin
s:=0;
for i:=1 to n do
begin
s:=s+a[i,j];
end;
if s<0 then
begin
gasit:=true;
st:=st+2*(0-s);
{for i:=1 to n do
begin
if x[i,j]<>1 then
a[i,j]:=0-a[i,j];
x[i,j]:=1;
end; }
end;
end;
end;
writeln(g,st);
close(f);
close(g);
end.