Cod sursa(job #195086)

Utilizator theratmantheratman theratman Data 16 iunie 2008 17:18:28
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.88 kb
var f,g:text;
    l1,c:array[1..16] of longint;
    a:array[1..32] of longint;
    n,m,l,i,x,xx,j,s,max,q:longint;
begin
assign(f,'flip.in');reset(f);
assign(g,'flip.out');rewrite(g);
read(f,n,m);
for i:=1 to n do
    for j:=1 to m do begin
        read(f,q);
        inc(l);
        l1[i]:=l1[i]+q;
        c[j]:=c[j]+q;
        end;
l:=0;
for i:=1 to n do begin
    inc(l);
    a[l]:=l1[i];
    end;
for i:=1 to m do begin
    inc(l);
    a[l]:=c[i];
    end;
max:=0;
for i:=1 to l do max:=max+a[i];
max:=max div 2;
for x:=1 to 1 shl l-1 do begin
    xx:=x;
    s:=max;
    for i:=1 to l do begin
        if xx mod 2=1 then begin
                           dec(s,a[i]);
                           inc(s,a[i]*-1);
                           end;
        xx:=xx div 2;
        end;
    if s>max then max:=s;
    end;
writeln(g,max);
close(f);
close(g);
end.