41 - ACM ICPC Regional 2005, Hangzhou, Preliminary - 1007
The transportation problem is to minimize the cost of transporting good from m source nodes to n destination nodes through arcs. Arcs are directed routes from source to destination which have no capacity limitation, but there is a cost associated with each arc for each unit of goods transported through. Each source has a supply amount, and each destination has a demand amount.
In this problem, the source nodes are numbered from 1 to m, and the destination nodes are numbered from 1 to n. There is one arc between each pair of the source node and the destination node. The cost of the arc originated from source node a (1 <= a <= m) to destination node b (1 <= b <= n) is a + b. The supply for each source nodes and the demand for each destination node are also given. You are going to calculate the maximal possible amount of goods that can be transported from source to destination, and also the minimized cost to achieve that goal.
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.
For each case, the numbers of source and destination nodes, m (1 <= m <= 10,000) and n (1 <= n <= 10,000), are given in the first line. The next line contains m integers, which are the supply amounts for each source, and the next line n integers, which are the demand amounts of each destination. All supply and demand amounts are non-negative numbers less than or equal to 10,000.
Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.
For each test case print in one line the two integers - the maximal amount of goods that can be transported to destination, and the minimized cost for transporting those goods. Separate them with a single space.