Link:
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1742
Topic:
Problem?
Lift Hopping
Time Limit:1 Second
Ted the bellhop: "I ' m coming up and if there isn ' t
A dead body by the time I get there, I ' ll make one
Myself. you! "
Robert Rodriguez, "Four rooms."
A skyscraper has no. than floors, numbered from 0 to 99. It has n (1<=n<=5) elevators which travel up and down at (possibly) different speeds. For all I in {1, 2,... n}, elevator number I takes Ti (1<=ti<=100) seconds to travel between any two adjacent s (going up or down). Elevators don't necessarily stop at every floor. What ' s worse, not every floor are necessarily accessible by a elevator.
You are are on floor 0 and would like to floor k as quickly as possible. Assume that you don't need to a wait to board the "I Elevator" for the "for simplicity" the operation of Switch ing an elevator on some floor always takes exactly a minute. Of course, both elevators have to stop in that floor. You are are forbiden from using the staircase. No one else is in the elevator with your, so don ' t have to stop if you don ' t want to. Calculate the minimum number of seconds required to get from floor 0 to floor K (passing floor k while inside a elevator That is does not stop there does not count as "getting to Floork").
Input
The input would consist a number of test cases. Each test case would begin with two numbers, N and K, on a line. The next line would contain the numbers T1, T2,... Tn. Finally, the next n lines'll contain sorted lists of integers-the of the The ' the ' the floors Number 1, the next one would list the floors visited by elevator number 2, etc.
Output
For each test case, output one is on a line by itself-the minimum number of seconds required to get to floor K from Floor 0. If It is impossible to do, print "impossible" instead.
Sample Input
2 30
10 5
0 1 3 5 7 9 11 13 15 20 99
4 13 15 19 20 25 30
2 30
10 1
0 5 10 12 14 20 25 30
2 4 6 8 10 12 14 22 25 28 29
3 50
10 50 100
0 10 30 40
0 20 30
0 20 50
1 1
2
0 2 4 6 8 10
Sample Output
275
285
3920
Impossible
Explanation of examples
In the ' the ', take elevator 1 to floor (130 seconds), then seconds to switch to elevator 2 and ride it to FL Oor seconds for the 275 seconds.
In the second example, take elevator 1-floor, switch to elevator 2 and ride it until floor 25. There, switch back to elevator 1 and get off at the "th" floor. The total?
10*10 + + 15*1 + 5*10 = 285 seconds.
In Example 3, take elevator 1-floor, then elevator 2 to floor and then elevator 3 to floor 50.
In the last example, the one elevator does is not stop at floor 1.