Cod sursa(job #29399)

Utilizator robitupaulRobitu Paul robitupaul Data 9 martie 2007 11:57:21
Problema Jocul Flip Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.94 kb
var a,b:array[0..16,0..16] of longint;
    n,m,i,j:integer;
    k,max:longint;
procedure citire;
begin
assign(input,'flip.in');
reset(input);
readln(n,m);
fillchar(a,sizeof(a),0);
for i:=1 to n do begin
    for j:=1 to m do begin
        read(a[i,j]);
    b[i,j]:=a[i,j];
    end;
    readln;
    end;
close(input);
end;

procedure init;
var i,j:integer;
begin
for i:=1 to n do
    for j:=1 to m do
        a[i,j]:=b[i,j];
end;

procedure rezolva;
var ii,jj:byte;
   l,c:longint;
begin
l:=0;c:=0;
k:=0;max:=0;
for ii:=0 to n do
    for jj:=0 to m do begin
        for j:=1 to m do a[ii,j]:=a[ii,j]*-1;
        for i:=1 to n do a[i,jj]:=a[i,jj]*-1;
        for i:=1 to n do
            for j:=1 to m do
                k:=k+a[i,j];
        if k>max then max:=k;
        k:=0;
        init;
        end;
end;

BEGIN
citire;
rezolva;
assign(output,'flip.out');
rewrite(output);
writeln(max);
closE(output);
end.