Cod sursa(job #1044816)

Utilizator VandheerManPopescu Alin VandheerMan Data 30 noiembrie 2013 14:44:22
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.01 kb
var
f:text;
s,max,l,l1:longint;
i,j,n,m:byte;
a:array[1..20,1..20] of longint;
begin
 assign(f,'flip.in');
 reset(f);
 readln(f,n,m);
 max:=0;
 for i:=1 to n do for j:=1 to m do begin read(f,a[i,j]);max:=max+a[i,j];end;
 close(f);

repeat
 s:=0;
 for i:=1 to n do begin for j:=1 to m do begin l:=l+a[i,j];
                                         l1:=l+(a[i,j]*(-1));
                                   end;
                        if l1>l then for j:=1 to m do a[i,j]:=a[i,j]*(-1);
                        end;
 l:=0;
 l1:=0;
 for j:=1 to m do begin for i:=1 to n do begin
                                         l:=a[i,j]+l;
                                         l1:=l1+(a[i,j]*(-1));
                                         end;
                        if l1>l then for i:=1 to n do a[i,j]:=a[i,j]*(-1);
                        end;
 for i:=1 to n do for j:=1 to m do s:=s+a[i,j];
 if s>max then max:=s;write(' ');
until s<max;
assign(f,'flip.out');
rewrite(f);
write(f,max);
close(f);


end.