Mai intai trebuie sa te autentifici.
Cod sursa(job #161646)
Utilizator | Data | 18 martie 2008 17:16:16 | |
---|---|---|---|
Problema | Jocul Flip | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.08 kb |
program flip;
var f,g:text;
a:array[1..16,1..16]of longint;
b:array[0..16]of byte;
s1,s2,max:longint;
x,i,j,n,m,aux:integer;
begin
assign(f,'flip.in');reset(f);
assign(g,'flip.out');rewrite(g);
readln (f,n,m);
for i:=1 to n do
begin
for j:=1 to m do read (f,a[i,j]);
readln(f);
end;
x:=1;
max:=0;
while x>0 do
begin
if b[x]<2 then b[x]:=b[x]+1;
if x=n then begin
s2:=0;
while j<=m do begin
s1:=0;
while i<n+1 do
begin
if b[i]=2 then s1:=s1-a[i,j]
else s1:=s1+a[i,j];
i:=i+1;
end;
if s1<aux then s2:=s2-s1
else s2:=s2+s1;
j:=j+1;
end;
if s2>max then max:=s2;
while b[x]=2 do
begin
x:=x-1;
end;
end
else begin
x:=x+1;
b[x]:=0;
end;
end;
writeln(g,max);
close(f);
close(g);
end.