Cod sursa(job #178435)

Utilizator llobyLodoaba Mihai lloby Data 14 aprilie 2008 16:39:46
Problema Jocul Flip Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.36 kb
Program flip;
type mat=array[1..16,1..16] of longint;
var t,f:text;
    n,m,i,j,suma: longint;
    a: mat;
Procedure sumare;
begin
    for i:=1 to m do
       for j:=1 to n do
          begin
            suma:=suma+a[i,j];
          end;
end;
Procedure coloane;
var i,j,max1,max: longint;
begin
    max:=0;
    max1:=0;
    for j:=1 to n do
    begin
     for i:=1 to m do
         if a[i,j]>0 then max:=max+a[i,j]
                     else max1:=max1+a[i,j];
         if abs(max1)>max then for i:=1 to m do
           begin
              a[i,j]:=a[i,j]*-1;
           end;
       max:=0;
       max1:=0;
    end;
end;
Procedure randuri;
var i,j,max1,max: longint;
begin
    max:=0;
    max1:=0;
    for i:=1 to m do
    begin
     for j:=1 to n do
         if a[i,j]>0 then max:=max+a[i,j]
                     else max1:=max1+a[i,j];
         if abs(max1)>max then for j:=1 to n do
           begin
              a[i,j]:=a[i,j]*-1;
           end;
        max:=0;
        max1:=0;
    end;
end;

begin
    assign(t,'flip.in'); reset(t);
    read(t,m,n);
    readln(t);
    for i:=1 to m do
     begin
      for j:=1 to n do
         read(t,a[i,j]);
         readln(t);
     end;
    close(t);
    suma:=0;
    coloane;
    randuri;
    sumare;
    assign(f,'flip.out'); rewrite(f);
    write(f,suma);
    close(f);
end.