Cod sursa(job #274568)

Utilizator andreirulzzzUPB-Hulea-Ionescu-Roman andreirulzzz Data 9 martie 2009 20:53:56
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.65 kb
program flip;
var i,j,k,p,s,smax,m,n:longint;
    a:array[1..16,1..16] of longint;
begin
smax:=0;
assign(input,'flip.in');
reset(input);
read(input,n,m);
for i:=1 to n do
for j:=1 to m do read(input,a[i,j]);
close(input);
for i:=1 to (1 shl m)-1 do begin
    s:=0;
    for j:=1 to n do begin
        p:=0;
        for k:=1 to m do
            if i and (1 shl(k-1))>0 then
               inc(p,-a[j,k])
            else inc(p,a[j,k]);
        if p<-p then
           inc(s,-p)
        else inc(s,p);
        end;
    if s>smax then smax:=s;
    end;
assign(output,'flip.out');
rewrite(output);
write(output,smax);
close(output);
end.