Pagini recente » Cod sursa (job #352248) | Cod sursa (job #2831380) | Cod sursa (job #147035) | Cod sursa (job #1017613) | Cod sursa (job #178435)
Cod sursa(job #178435)
Program flip;
type mat=array[1..16,1..16] of longint;
var t,f:text;
n,m,i,j,suma: longint;
a: mat;
Procedure sumare;
begin
for i:=1 to m do
for j:=1 to n do
begin
suma:=suma+a[i,j];
end;
end;
Procedure coloane;
var i,j,max1,max: longint;
begin
max:=0;
max1:=0;
for j:=1 to n do
begin
for i:=1 to m do
if a[i,j]>0 then max:=max+a[i,j]
else max1:=max1+a[i,j];
if abs(max1)>max then for i:=1 to m do
begin
a[i,j]:=a[i,j]*-1;
end;
max:=0;
max1:=0;
end;
end;
Procedure randuri;
var i,j,max1,max: longint;
begin
max:=0;
max1:=0;
for i:=1 to m do
begin
for j:=1 to n do
if a[i,j]>0 then max:=max+a[i,j]
else max1:=max1+a[i,j];
if abs(max1)>max then for j:=1 to n do
begin
a[i,j]:=a[i,j]*-1;
end;
max:=0;
max1:=0;
end;
end;
begin
assign(t,'flip.in'); reset(t);
read(t,m,n);
readln(t);
for i:=1 to m do
begin
for j:=1 to n do
read(t,a[i,j]);
readln(t);
end;
close(t);
suma:=0;
coloane;
randuri;
sumare;
assign(f,'flip.out'); rewrite(f);
write(f,suma);
close(f);
end.