Cod sursa(job #1585439)

Utilizator DoubleNyNinicu Cristian DoubleNy Data 30 ianuarie 2016 23:57:20
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.31 kb
program flip;
 var suma,n,m,i,j,k:integer;
     a:array[1..16,1..16] of integer;


 procedure control;
  var sumaNrNegative,sumaNrPozitive:integer;
  begin
   sumaNrNegative:=0;
   sumaNrPozitive:=0;
   for i:=1 to n do
    begin
      for j:=1 to m do
       if a[i,j]<0 then sumaNrNegative:=sumaNrNegative+a[i,j]
       else if a[i,j]>0 then sumaNrPozitive:=sumaNrPozitive+a[i,j];

       if abs(sumaNrNegative)>sumaNrPozitive then
        for k:=1 to m do a[i,k]:=a[i,k]*(-1);
      sumaNrNegative:=0;
      sumaNrPozitive:=0;
    end;

   for j:=1 to m do
    begin
      for i:=1 to n do
       if a[i,j]<0 then sumaNrNegative:=sumaNrNegative+a[i,j]
       else if a[i,j]>0 then sumaNrPozitive:=sumaNrPozitive+a[i,j];

       if abs(sumaNrNegative)>sumaNrPozitive then
        for k:=1 to n do a[k,j]:=a[k,j]*(-1);
        sumaNrNegative:=0;
        sumaNrPozitive:=0;
    end;



  end;



begin
 suma:=0;
 assign(input,'flip.in'); reset(input);
 readln(n,m);
 close(input);
 for i:=1 to n do
  for j:=1 to m do read(a[i,j]);
  control;
 { for i:=1 to n do
   begin
    for j:=1 to m do write(a[i,j],' ');
    writeln;
   end;
 writeln; }
 for i:=1 to n do
  for j:=1 to m do
   suma:=suma+a[i,j];
 assign(output,'flip.out'); rewrite(output);
 write(suma);
 close(output);
end.