Pagini recente » Cod sursa (job #5934) | Cod sursa (job #567859) | Cod sursa (job #1735292) | Cod sursa (job #67234) | Cod sursa (job #2421075)
var f:textfile;
n, m, i, j, col, r: integer;
maxRand, sumaRand, maxCol, sumaCol, s:longint;
arr: array[1..16, 1..16] of longint;
begin
assign(f, 'flip.in');
reset(f);
read(f, n);
readln(f, m);
for i:=1 to n do
begin
for j:=1 to m do
read(f, arr[i,j]);
readln(f);
end;
close(f);
maxRand:=0;
for j:=1 to m do maxRand:=arr[1,j]*(-1)+maxRand;
r:=1;
for i:=1 to n do
begin
sumaRand:=0;
for j:=1 to m do
sumaRand:=arr[i,j]*(-1)+sumaRand;
if sumaRand>maxRand then begin maxRand:=sumaRand; r:=i; end;
end;
maxCol:=0;
for i:=1 to n do maxCol:=arr[i,1]*(-1)+maxCol;
col:=1;
for i:=1 to n do
begin
sumaCol:=0;
for j:=1 to m do
sumaCol:=arr[j,i]*(-1)+sumaCol;
if sumaCol>maxCol then begin maxCol:=sumaCol; col:=i; end;
end;
{writeln(r);
writeln(col);}
for i:=1 to m do arr[r,i]:=arr[r,i]*(-1);
for i:=1 to n do arr[i, col]:=arr[i,col]*(-1);
{for i:=1 to n do
begin
for j:=1 to m do
write(arr[i,j], ' ');
writeln;
end; }
s:=0;
for i:=1 to n do
for j:=1 to m do
s:=s+arr[i,j];
assign(f, 'flip.out');
rewrite(f);
write(f, s);
close(f);
end.