#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" usingnamespace std; #define MAXN 12 int n , m; int A[MAXN][MAXN] , B[MAXN][MAXN]; int dp[1 << 20]; intwork( int sta , int w ){ if( ~dp[sta] ) return dp[sta]; dp[sta] = w ? -0x3f3f3f3f : 0x3f3f3f3f; int x = n , y = 0; for( int i = 0 ; i < n + m - 1 ; ++ i ) { if( sta & ( 1 << i ) ) -- x; else ++ y; if( ( ( sta >> i ) & 3 ) != 1 ) continue; // LefT,DowN // LefT DowN -> DowN LefT if( w ) dp[sta] = max( dp[sta] , work( sta ^ ( 3 << i ) , w ^ 1 ) + A[x + 1][y + 1] ); else dp[sta] = min( dp[sta] , work( sta ^ ( 3 << i ) , w ^ 1 ) - B[x + 1][y + 1] ); } return dp[sta]; } intmain(){ cin >> n >> m; for( int i = 1 ; i <= n ; ++ i ) for( int j = 1 ; j <= m ; ++ j ) scanf("%d",&A[i][j]); for( int i = 1 ; i <= n ; ++ i ) for( int j = 1 ; j <= m ; ++ j ) scanf("%d",&B[i][j]); memset( dp , -1 , sizeof dp ); dp[( 1 << n ) - 1 << m] = 0; cout << work( ( 1 << n ) - 1 , 1 ) << endl; }