import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; void main() { auto s = readln.split.map!(to!int); auto H = s[0]; auto W = s[1]; auto A = iota(H).map!(_ => readln.split.map!(to!long).array).array; auto R = readln.split.map!(to!long).array; auto C = readln.split.map!(to!long).array; foreach (i; 0..H) A[i] ~= R[i] - A[i].sum; A.sort!"a.back > b.back"; long csum = 0; foreach (j; 0..W) foreach (i; 0..H) C[j] -= A[i][j]; foreach (j; 0..W) csum += max(0L, C[j]); auto ans = csum; auto tmp = csum; foreach (i; 0..H) { tmp += A[i].back; foreach (j; 0..W) { C[j] += A[i][j]; tmp += max(0L, C[j] - max(C[j] - A[i][j], 0L)); } ans = max(ans, tmp); } ans.writeln; }