#P4015. 运输问题

运输问题

Description

Company WW has mm warehouses and nn retail stores. The ii-th warehouse has aia_i units of goods; the jj-th retail store needs bjb_j units of goods.

The supply and demand are balanced, i.e., i=1mai=j=1nbj\sum\limits_{i=1}^{m}a_i=\sum\limits_{j=1}^{n}b_j.

The cost to transport each unit of goods from the ii-th warehouse to the jj-th retail store is ci,jc_{i,j}.

Design a transportation plan to ship all goods from the warehouses to the retail stores so that the total transportation cost is minimized.

Input Format

Line 1 contains 2 positive integers mm and nn, representing the number of warehouses and retail stores, respectively.

The next line contains mm positive integers aia_i, where the ii-th warehouse has aia_i units of goods.

The following line contains nn positive integers bjb_j, where the jj-th retail store requires bjb_j units of goods.

The next mm lines each contain nn integers, representing the per-unit transportation cost ci,jc_{i,j} from the ii-th warehouse to the jj-th retail store.

Output Format

Output two lines: the minimum total transportation cost and the maximum total transportation cost.

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

Hint

1n,m1001 \leq n, m \leq 100.

Translated by ChatGPT 5