Cod sursa(job #32915)

Utilizator adella_stanciuStanciu Adela adella_stanciu Data 18 martie 2007 18:23:42
Problema Jocul Flip Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.94 kb
var f,g:text;n,m,i,j:byte;s_n,s_p,s:longint;
    mat:array[1..16,1..16] of longint;
begin
     assign(f,'flip.in');reset(f);assign(g,'flip.out');rewrite(g);
     readln(f,n,m);
     for i:=1 to n do begin
         s_n:=0;s_p:=0;
         for j:=1 to m do begin
             read(f,mat[i,j]);
             if mat[i,j]<0 then inc(s_n,mat[i,j])
                           else inc(s_p,mat[i,j]);
         end;
         if s_p<abs(s_n) then for j:=1 to m do
                                  mat[i,j]:=mat[i,j]*(-1);
     end;
     for i:=1 to m do begin
         s_n:=0;s_p:=0;
         for j:=1 to n do
             if mat[j,i]<0 then inc(s_n,mat[j,i])
                           else inc(s_p,mat[j,i]);
         if s_p<abs(s_n) then for j:=1 to n do
                                  mat[j,i]:=mat[j,i]*(-1);
     end;
     for i:=1 to n do
         for j:=1 to m do
             s:=s+mat[i,j];
     writeln(g,s);
     close(g);
end.