Cod sursa(job #268873)
Utilizator | Data | 1 martie 2009 22:48:13 | |
---|---|---|---|
Problema | Jocul Flip | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.75 kb |
program joc_flip;
var f:text;
a:array[1..20,1..20]of longint;
st:array[0..100]of longint;
i,j,m,n,h,q:longint;
s,s1,max,suma:longint;
as:boolean;
begin
assign(f,'flip.in');reset(f);
readln(f,m,n);
for i:=1 to m do
begin
for j:=1 to n do
read(f,a[i,j]);
readln(f);
end;
close(f);
max:=-2000000000;
j:=1;
st[j]:=-1;
while j>0 do
begin
if st[j]<1 then begin
st[j]:=st[j]+1;
as:=true;
end
else as:=false;
if as then begin
if j=m then begin
for i:=1 to m do
if st[i]=0 then for h:=1 to n do
a[i,h]:=a[i,h]*(-1);
suma:=0;
for i:=1 to n do
begin
s:=0;
for h:=1 to m do
s:=s+a[h,i];
if s>0 then suma:=suma+s
else suma:=suma-s;
end;
if suma>max then max:=suma;
end ;
end
else begin
j:=j-1;
if st[j]=0 then for i:=1 to n do
a[j,i]:=a[j,i]*(-1);
end;
end;
assign(f,'flip.out');rewrite(f);
writeln(f,max);
close(f);
end.