You are on page 1of 2

28/07/2022, 22:35 HackerRank Question - Devaki and Her Job

25m left

1. Devaki and Her Job

Devaki has just started a part-time job as a milk delivery executive in a reputed company. Every
morning, she is given a map of all the places where milk needs to be delivered, and dropped at
ALL
one of those places (based on her choice) in the company van. From there, she has to travel by
herself to all the locations and complete the deliveries. Since the locations are inter-connected in
many ways, she can freely choose the location sequence and the route to take such that she
visits each city exactly once and deliver the milk to all the cities.

Devaki incurs a cost of Rs. 1 for every km she travels. She is however paid a flat Rs. 5 for each
1
km on the map given to her, irrespective of what routes she takes. After a couple of days, Devaki
realised that she can maximise her savings by choosing the best route possible i.e. one where
2 she spends the least on travel. She is wondering exactly how much she can save if she uses the
best route.

3 Can you help Devaki with a program that tells her how much she can save if she uses the best
route, while ensuring she delivers milk to all her customers?

 
4 Note: It is guaranteed that there is a path such that Devaki can deliver milk to all cities by visiting
each city exactly once.

5 Read the input from STDIN and print the output to STDOUT. Do not print arbitrary strings
anywhere in the program, as these contribute to the standard output and test cases will fail.

6 Constraints:

3 <= number of locations <= 16

0 <= km distance between two locations <= 1000

Input Format:

The first line of input consists of an integer N, which is the number of locations to which Devaki
8
needs to deliver milk.

The next N lines consist of N integers each separated by space, which give the distance between
9 two locations (a non-zero value if a direct path exists between the two locations, else zero).
The ith line gives the distance of the ith location from each of the N locations.

10 Output Format:

A single line of output consists of the total amount that Devaki can save by using the best path.

11 Sample Input 1:

0 5 11 0 1

12 5 0 0 3 5

11 0 0 3 11

0 3 3 0 7

13
1 5 11 7 0

https://www.hackerrank.com/test/880ch6t5s60/questions/53079c7t1il 1/2
28/07/2022, 22:35 HackerRank Question - Devaki and Her Job

https://www.hackerrank.com/test/880ch6t5s60/questions/53079c7t1il 2/2

You might also like