Pagini recente » Cod sursa (job #3226420) | Cod sursa (job #564874) | Cod sursa (job #340116) | Cod sursa (job #696263) | Cod sursa (job #35163)
Cod sursa(job #35163)
{
Jocul Flip
Versiunea 4.00
}
Program Flip;
Type matrice = array[1..16,1..16] of Longint;
Var a : matrice;
n, m, i, j : Byte;
suma, s1, s2 : Longint;
Procedure MaxL( i : Integer );
Var s1, s2 : Longint;
j : Integer;
Begin
s1 := 0;
s2 := 0;
For j := 1 to m do
Begin
s1 := s1 + a[i,j];
s2 := s2 - a[i,j];
End;
if s2 > s1 then
For j := 1 to m do
a[i,j] := -a[i,j];
End;
Procedure MaxC( j : Integer );
Var s1, s2 : Longint;
i : Integer;
Begin
s1 := 0;
s2 := 0;
For i := 1 to n do
Begin
s1 := s1 + a[i,j];
s2 := s2 - a[i,j];
End;
if s2 > s1 then
For i := 1 to n do
a[i,j] := -a[i,j];
End;
Begin
Assign( input, 'flip.in' );
Reset( input );
Readln( n, m );
For i := 1 to n do
Begin
For j := 1 to m do
Read( a[i,j] );
Readln;
End;
Close( input );
For i := 1 to n do
MaxL( i );
For j := 1 to m do
MaxC( j );
suma := 0;
For i := 1 to n do
For j := 1 to m do
suma := suma + a[i,j];
Assign( output, 'flip.out' );
Rewrite( output );
Writeln( suma );
Close( output );
End.