Cod sursa(job #1198940)

Utilizator ianic1999Ianic Umanschii ianic1999 Data 17 iunie 2014 18:10:09
Problema Jocul Flip Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.78 kb
type tabel=array[1..20,1..20]of longint;
var t,x:tabel;
    n,m,i,j,smax,s,k:longint;
begin
 assign(input,'flip.in');
 reset(input);
   readln(n,m);
   for i:=1 to n do
    begin
     for j:=1 to m do
      read(t[i,j]);
      readln;
    end;
 close(input);

 smax:=0;
 s:=0;
 for i:=1 to n do
  begin
   for j:=1 to m do
    begin
     s:=s+t[i,j];
    end;
    if s<0 then for k:=1 to m do t[i,k]:=t[i,k]*(-1);
    s:=0;
  end;
   s:=0;
 for i:=1 to n do
  begin
   for j:=1 to m do
    begin
     s:=s+t[j,i];
    end;
    if s<0 then for k:=1 to n do t[k,i]:=t[k,i]*(-1);
    s:=0;
  end;
  for i:=1 to n do
   for j:=1 to m do
    smax:=smax +t[i,j];

    assign(output,'flip.out');
    rewrite(output);
     write(smax);
    close(output);
end.