#graph802. 运输问题

运输问题

Transportation Problem

Problem Source

Network Flow 24 Problems

Problem Description

Company WW has mm warehouses and nn retail stores. Warehouse ii holds aia_i units of goods; retail store jj needs bjb_j units of goods.

Supply and demand are balanced, that is $\sum\limits_{i=1}^{m} a_i = \sum\limits_{j=1}^{n} b_j$.

Shipping one unit of goods from warehouse ii to retail store jj costs cijc_{ij}.

Design a plan that ships all goods from the warehouses to the retail stores, minimizing the total shipping cost.

Input Format

The first line contains two positive integers m,n (1≤m,n≤100)m, n\ (1 \le m, n \le 100), the number of warehouses and retail stores.

The next line contains mm positive integers aia_i, the amount of goods in warehouse ii.

The following line contains nn positive integers bjb_j, the amount of goods needed by retail store jj.

The next mm lines each contain nn integers, the cost cij (ci,j≥1)c_{ij}\ (c_{i,j} \ge 1) of shipping one unit from warehouse ii to retail store jj.

Output Format

Output two lines: the minimum total shipping cost and the maximum total shipping cost, respectively.

The answer is guaranteed not to exceed 10910^9.

Sample Input

2 3
220 280
170 120 210
77 39 105
150 186 122

Sample Output

48500
69140