Pagini recente » Cod sursa (job #930448) | Cod sursa (job #1547147) | Autentificare | Cod sursa (job #2778259) | Cod sursa (job #11068)
Cod sursa(job #11068)
var
ertek:longint;
be,ki:text;
i,j:word;
n,m:byte;
matr:array[1..16,1..16]of longint;
px,py,x,y:array[1..16]of longint;
nx,ny:array[1..16]of longint;
begin
assign(be,'flip.in');
reset(be);
readln(be,n,m);
for i:=1 to n do begin
for j:=1 to m do begin
read(be,matr[i,j]);
if matr[i,j]>=0 then px[i]:=px[i]+matr[i,j]
else nx[i]:=nx[i]+abs(matr[i,j]);
end;
if nx[i]>px[i] then begin x[i]:=nx[i]-px[i];
for j:=1 to m do
matr[i,j]:=-matr[i,j];
end
else x[i]:=px[i]-nx[i];
readln(be);
end;
close(be);
for i:=1 to n do begin
for j:=1 to n do begin
if matr[j,i]>=0 then py[i]:=py[i]+matr[j,i]
else ny[i]:=ny[i]+abs(matr[j,i]);
end;
if ny[i]>py[i] then begin y[i]:=ny[i]-py[i];
for j:=1 to m do
matr[j,i]:=-matr[j,i];
end
else y[i]:=py[i]-ny[i];
end;
ertek:=0;
for i:=1 to m do
ertek:=ertek+y[i];
assign(ki,'flip.out');
rewrite(ki);
write(ki,ertek);
close(ki);
end.