第31届ICPC北京赛区网络试题(I)
Lazy men's service(I) Time Limit:10S Memory Limit:32768K
Description
There is a service station specially designed for lazy men in the world. Like other service stations, this station also has waiters and counters. However, because it is opened for lazy men, who are only willing to come to the nearest counter, and because the station lacks waiters, waiters always have to move among counters to provide service. What's more, if lazy men are not serviced in time, they will ask for troubles, which make waiters complaint. Luckily, these customers are so lazy that they leave as soon as they gain service, and it takes nearly no time for the consult process. So, waiters hardly do anything other than moving among counters.
The station has a website. Lazy men always visit the website to inquire their own service time and counter. Then, they come to counter when their service time comes. Every morning, manager of the station can get a list of today's visitors. The website only arranges one lazy man to consult at each moment. The website designs so good that waiters have enough time to move between any of the two counters during each of the two moments.
You are a new-hired manager. You are working to solve the employees' problems. As the internal paths among counters are complex, it takes different level of energy to move from any counter to the other counters. You find out that the complaint issue can be solved if waiters moved efficiently such that the total energy cost is minimized. So, you decide to reconstruct the website, arrange a certain waiter for each moment and calculate the minimized level of energy cost.
Input
Input contains several cases.
Input contains what happens to the service station in several days.
For each day, Line 1 contains three number, specifying there are n lazy men to service, m waiters on work and p open counters (1 <= n <= 200, 1 <= m <= 100, 1 <= p <= 100).
Each line between Line 2 and Line p+1 contains p integers. The j-th number of Line i+1 is ci,j, specifying the energy cost of waiters who move from counter i to counter j. ci,i=0, ci,j may not equal to cj,i(0 <= ci,j <= 105).
Line p+2 contains m integers. The i-th number si indicates the initial counter where waiter i is in (1 <= si <= p).
Line p+3 contains n integers. The i-th number di indicates the counter selected by the lazy man who comes on time i (1 <= di <= p).
The last line of input contains a zero.
Output
For each day, output minimized energy cost and n numbers, the i-th of which indicates the waiter's number who services the lazy man coming on time i.
Sample Input
3 2 4
0 1 5 6
2 0 100 100
100 100 0 100
100 100 100 0
1 2
1 3 4
3 2 4
0 1 5 6
2 0 100 100
100 100 0 100
100 100 100 0
1 2
1 3 4
0
Sample Output
Case 1:
13
2 1 2
Case 2:
13
2 1 2