FISHER - Fishmonger

no tags 

A FishmongerA fishmonger wants to bring his goods from the port to the market. On his route he has to traverse an area with many tiny city states. Of course he has to pay a toll at each border.

Because he is a good business man, he wants to choose the route in such a way that he has to pay as little money for tolls as possible. On the other hand, he has to be at the market within a certain time, otherwise his fish start to smell.

Input

The first line contains the number of states n and available time t. The first state is the port, the last state is the market. After this line there are n lines with n numbers each, specifying for each state the travel time to the i-th state. This table is terminated with an empty line. The table of the tolls follows in the same format.

n is at least 3 and at most 50. The time available is less than 1000. All numbers are integers.

There are many test cases separated by an empty line. Input terminates with number of states and time equal 0 0.

Output

For each test case your program should print on one line the total amount of tolls followed by the actual travelling time.

Example

Sample input:
4 7
0 5 2 3
5 0 2 3
3 1 0 2
3 3 2 0

0 2 2 7
2 0 1 2
2 2 0 5
7 2 5 0

0 0

Sample output:
6 6

This corresponds to the following situation, the connections are labeled with (time, toll):


hide comments
Ahmed Hussein: 2016-08-18 17:26:31

50 * 50 * 1000 iterative will pass

Shivang Badola: 2016-07-01 10:16:27

Take care that you read TIME first then TOLLS..cost me many WA.

PARTH SHARMA: 2016-06-23 14:45:27

dp in time :))

aspro: 2016-05-16 07:00:31

TLE with recursion(DFS)...solved with DP(knapsack)...
but still cant figure the approach with dijkstra :(
got it......thanx narutorocks

Last edit: 2016-06-15 09:24:32
epsilon: 2016-01-26 07:15:53

can someone please explain the input format

Last edit: 2016-01-26 07:16:14
sudhanshu monga: 2015-12-17 15:48:38

woah ! what a knapsack ! :D

Siddharth Singh: 2015-11-10 15:55:40

why is 3 7 not the answer ???

:.Mohib.:: 2015-11-08 09:22:25

Beautiful :)

Last edit: 2015-11-08 14:57:21
naruto09: 2015-10-06 20:36:39

getting WA..can't find the problem with my code...please help..my code : http://ideone.com/f0Vrxk

SangKuan: 2015-08-17 10:44:56

do not understand this problem...


Added by:MichaƂ Czuczman
Date:2004-07-07
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Swiss Olympiad in Informatics 2004