Cod sursa(job #1996458)

Utilizator _Victor_Victor Ciobanu _Victor_ Data 1 iulie 2017 16:38:26
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.75 kb
Program Flip;
type max =1..16;
tab = array[max,max] of -1000000..1000000;
var n,m,i,j:max;
fl:tab;
a,s:longint;
procedure SRand(var fl: tab; r:max);
var i: max;
begin
for i:=1 to m do
 fl[r,i]:= -fl[r,i];
end;
procedure SCol(var fl: tab; r:max);
var i: max;
begin
for i:=1 to n do
 fl[i,r]:= -fl[i,r];
end;
procedure Evaluare;
var i,j:max;
begin
for i:= 1 to n do
for j:=1 to m do
s:= s+fl[i,j];
end;
begin
readln(n,m);
for i:=1 to n do begin
for j:=1 to m do
 read(fl[i,j]);
readln;
end;
for i:=1 to n do begin
 a:=0;
 for j:=1 to m do
  a:= a + fl[i,j];
 if a<0 then SRand(fl,i);
end;
for j:=1 to m do begin
 a:=0;
 for i:=1 to n do
  a:= a + fl[i,j];
 if a<0 then SCol(fl,j);
end;
 Evaluare;
writeln(s);
readln;
end.