Pagini recente » Cod sursa (job #2023650) | Cod sursa (job #2887987) | Cod sursa (job #2654540) | Cod sursa (job #2040274) | Cod sursa (job #573064)
Cod sursa(job #573064)
var
a:array[1..16,1..16] of longint;
n,m,i,j:integer;
suma:longint;
procedure change_c(col:integer);
var
ii:integer;
begin
for ii:=1 to n do
a[ii,col]:=a[ii,col]*(-1);
end;
procedure coloana;
var
neg,poz:longint;
begin
for i:=1 to m do begin
poz:=0;
neg:=0;
for j:=1 to n do begin
if a[j,i] > 0 then poz:=poz+a[j,i] else neg:=neg+a[j,i];
if neg*(-1) > poz then change_c(i);
end;
end;
end;
procedure change_l(lin:integer);
var
ii:integer;
begin
for ii:=1 to m do
a[lin,ii]:=a[lin,ii]*(-1);
end;
procedure linie;
var
neg,poz:longint;
begin
for i:=1 to n do begin
poz:=0;
neg:=0;
for j:=1 to n do begin
if a[i,j] > 0 then poz:=poz+a[i,j] else neg:=neg+a[i,j];
if neg*(-1) > poz then change_l(i);
end;
end;
end;
begin
assign(input,'flip.in');reset(input);
assign(output,'flip.out');rewrite(output);
readln(n,m);
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
coloana;
linie;
suma:=0;
for i:=1 to n do
for j:=1 to m do
suma:=a[i,j]+suma;
writeln(suma);
end.