Cod sursa(job #573194)

Utilizator dutzu93Vlad Vedinas dutzu93 Data 5 aprilie 2011 23:38:53
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.67 kb
program infoarena_flip;
var i,j,k2,m,n,s,smax,j1,x1:longint;
    a:array[1..16,1..16] of longint;

begin
assign(input,'flip.in');
reset(input);
read(n);readln(m);
for i:=1 to n do
 for j:=1 to m do
  read(a[i,j]);
close(input);
smax:=0;

j1:=1 shl m;
j1:=j1-1;

 for k2:=0 to j1 do
  begin
   s:=0;
   for i:=1 to n do
    begin
    x1:=0;
    for j:=1 to m do
      if k2 and (1 shl (j-1))>0 then x1:=x1-a[i,j]
                                else x1:=x1+a[i,j];

     if x1<0 then s:=s-x1
             else s:=s+x1;
    end;
   if s>smax then smax:=s;
  end;



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

end.