Pagini recente » Cod sursa (job #2844004) | Cod sursa (job #1769377) | Cod sursa (job #236513) | Cod sursa (job #2621233) | Cod sursa (job #582137)
Cod sursa(job #582137)
var a:array[1..16,1..16] of longint;
b,c:array[1..16] of boolean;
i,j,x,y,n,m,s,neg,poz:longint;
f,g:text;
begin
assign(f,'flip.in');reset(f);
assign(g,'flip.out');rewrite(g);
readln(f,n,m);
for i:=1 to n do begin
for j:=1 to m do read(f,a[i,j]);
readln(f);
end;
i:=0;
x:=0;
y:=0;
repeat
inc(i);
neg:=0;
poz:=0;
for j:=1 to m do
if a[i,j]<0 then neg:=neg+abs(a[i,j])
else poz:=poz+a[i,j];
inc(x);
if neg>poz then b[x]:=true
else b[x]:=false;
until i>=n;
i:=0;
repeat
inc(i);
neg:=0;
poz:=0;
for j:=1 to n do
if a[j,i]<0 then neg:=neg+abs(a[j,i])
else poz:=poz+a[j,i];
inc(y);
if neg>poz then c[y]:=true
else c[y]:=false;
until i>=m;
for i:=1 to x do
if b[i]=true then
for j:=1 to m do a[i,j]:=a[i,j]*(-1);
for i:=1 to y do
if c[i]=true then
for j:=1 to n do a[j,i]:=a[j,i]*(-1);
s:=0;
for i:=1 to n do
for j:=1 to m do s:=s+a[i,j];
write(g,s);
close(f);
close(g);
{write(s);
readln;}
end.