Pagini recente » Cod sursa (job #1815272) | Cod sursa (job #2888104) | Cod sursa (job #1645699) | Cod sursa (job #416356) | Cod sursa (job #32915)
Cod sursa(job #32915)
var f,g:text;n,m,i,j:byte;s_n,s_p,s:longint;
mat:array[1..16,1..16] of longint;
begin
assign(f,'flip.in');reset(f);assign(g,'flip.out');rewrite(g);
readln(f,n,m);
for i:=1 to n do begin
s_n:=0;s_p:=0;
for j:=1 to m do begin
read(f,mat[i,j]);
if mat[i,j]<0 then inc(s_n,mat[i,j])
else inc(s_p,mat[i,j]);
end;
if s_p<abs(s_n) then for j:=1 to m do
mat[i,j]:=mat[i,j]*(-1);
end;
for i:=1 to m do begin
s_n:=0;s_p:=0;
for j:=1 to n do
if mat[j,i]<0 then inc(s_n,mat[j,i])
else inc(s_p,mat[j,i]);
if s_p<abs(s_n) then for j:=1 to n do
mat[j,i]:=mat[j,i]*(-1);
end;
for i:=1 to n do
for j:=1 to m do
s:=s+mat[i,j];
writeln(g,s);
close(g);
end.