Magazine Delivery
Time limit1sMemory limit128 MB
Three cars start at L1 and must deliver to locations in strict order 2,3,...,N, with only one car moving at a time; minimize the total completion time.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Shortest path, Implementation, Greedy
- Solved
- No attempts yet
Problem
A courier company in Tehran must deliver magazines to locations in the city, labeled through . The company assigns 3 cars to the job. At time , all 3 cars and the magazines are at . There are plenty of magazines at , and a car may load as many as it wants. A copy must be delivered to every location, subject to the following rules:
- For every , the delivery to may happen only after the delivery to is complete.
- At any moment only one of the three cars is driving; the other two rest at their current locations.
The time for a car to travel between and (in either direction) is a positive integer .
Arrange the delivery schedule so that the time by which all locations have received magazines is minimized. Write a program to compute this minimum completion time.
Input
The input contains instances of the problem (). The first line is . The instances follow one after another.
Each instance begins with a line containing (). The next lines describe the distances: line (for ) contains for , separated by spaces. Distances are symmetric ().
Output
Print lines, one per instance. Each line is the minimum time needed to deliver magazines to all locations of that instance.