// yuki 957 植林 // 2019.12.21 bal4u #include #include #include typedef long long ll; int getchar_unlocked(void); #define gc() getchar_unlocked() //#define gc() getchar() int in() { // 整数の入力 int n = 0; int c; do c = gc(); while (isspace(c)); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } int g[305][305]; ll sr[305], sc[305]; int R[305], C[305]; int main() { int r, c, H, W; ll ans, s, t; H = in(), W = in(); for (r = 0; r < H; ++r) for (c = 0; c < W; ++c) { g[r][c] = in(), sr[r] += g[r][c]; } for (c = 0; c < W; ++c) for (r = 0; r < H; ++r) { sc[c] += g[r][c]; } for (r = 0; r < H; ++r) R[r] = in(); for (c = 0; c < W; ++c) C[c] = in(); ans = 0; for (r = 0; r < H; ++r) { if ((t = R[r] - sr[r]) > 0) ans += t; } s = 0; for (c = 0; c < W; ++c) { if ((t = C[c] - sc[c]) > 0) s += t; } if (s > ans) ans = t; s = 0; for (r = 0; r < H; ++r) for (c = 0; c < W; ++c) { t = (ll)R[r] + C[c] + (ll)g[r][c] - (sr[r] + sc[c]); if (t > 0) s += t; } if (s > ans) ans = s; printf("%lld\n", ans); return 0; }