Pagini recente » Cod sursa (job #176902) | Cod sursa (job #1060603) | Cod sursa (job #49279) | Cod sursa (job #899786) | Cod sursa (job #255239)
Cod sursa(job #255239)
program alex;
var f:text;
a:array[1..20,1..20]of longint;
st:array[0..100]of longint;
i,j,m,n,h,q:longint;
s,s1,max,suma:longint;
as:boolean;
begin
assign(f,'flip.in');reset(f);
readln(f,m,n);
for i:=1 to m do
begin
for j:=1 to n do
read(f,a[i,j]);
readln(f);
end;
close(f);
max:=-2000000000;
j:=1;
st[j]:=-1;
while j>0 do
begin
if st[j]<1 then begin
st[j]:=st[j]+1;
as:=true;
end
else as:=false;
if as then begin
if j=m then begin
for i:=1 to m do
if st[i]=0 then for h:=1 to n do
a[i,h]:=a[i,h]*(-1);
suma:=0;
for i:=1 to n do
begin
s:=0;
s1:=0;
for h:=1 to m do
if a[h,i]>0 then s:=s+a[h,i]
else s1:=s1+(a[h,i]*(-1));
if s1>s then suma:=suma+s1-s
else suma:=suma+s-s1;
end;
if suma>max then max:=suma;
end
else begin
j:=j+1;
st[j]:=-1;
end;
end
else begin
j:=j-1;
if st[j]=0 then for i:=1 to n do
a[j,i]:=a[j,i]*(-1);
end;
end;
assign(f,'flip.out');rewrite(f);
writeln(f,max);
close(f);
end.