#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 #define Inf48 5000000000000 int main(){ int h,w; cin>>h>>w; vector g(h,vector(w)); long long ans = 0; rep(i,h){ rep(j,w){ cin>>g[i][j]; ans += g[i][j]; } } vector rc0(h+w,Inf48); auto rc1 = rc0; rep(i,h+w){ long long t; cin>>t; rc1[i] -= t; } rep(i,h){ rep(j,w){ rc0[i] -= g[i][j]; } } mf_graph G(h+w + 2); int s = (h+w); int t = s+1; rep(i,h+w){ G.add_edge(s,i,rc0[i]); G.add_edge(i,t,rc1[i]); } rep(i,h){ rep(j,w){ G.add_edge(h+j,i,g[i][j]); } } //cout<