Pagini recente » Cod sursa (job #635736) | Cod sursa (job #473392) | Cod sursa (job #2950249) | Cod sursa (job #283440) | Cod sursa (job #161264)
Cod sursa(job #161264)
var a:array[1..16,1..16] of longint;
i,j,n,m,x:byte;
s,max,ss:longint;
f,g:text;
b:array[0..16] of byte;
begin
assign(f,'flip.in');reset(f);
assign(g,'flip.out');rewrite(g);
readln(f,n,m);
for i:=1 to n do begin
for j:=1 to m do
read(f,a[i,j]);
readln(f);
end;
x:=1;
for i:=1 to n do
b[i]:=0;
while x>0 do begin
if b[x]<2 then b[x]:=b[x]+1;
if x=n then begin
ss:=0;
for j:=1 to m do begin
s:=0;
for i:=1 to n do begin
if b[i]=2 then
s:=s-a[i,j] else
s:=s+a[i,j];
end;
if s<0 then ss:=ss-s
else ss:=ss+s;
end;
if ss>max then max:=ss;
while b[x]=2 do begin
x:=x-1;
end;
end else begin
x:=x+1;
b[x]:=0;
end
end;
writeln(g,max);
close(f);
close(g);
end.