Expedition Plans
Time limit10sMemory limit1024 MB
Given sailing, diving, and fixing costs along a cable, find the diagnosis order of repeaters that minimizes the worst-case total cost over all faulty segments.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Intervals
- Solved
- No attempts yet
Problem
The International Company of Pipes and Cables runs an internet cable across the Pacific. However, it has stopped working! But wait, no need to panic, this is not unexpected, being sometimes caused by shark attacks. The cable is composed of a sequence of segments, with a repeater between each pair of consecutive segments. Repeaters are identified by distinct integers from to , from left to right, according to their positions within the cable.
A signal is transmitted from left to right along the cable. A repeater is said to be offline if no signal reaches the repeater; this indicates that there is a faulty segment before the repeater. On the contrary, a repeater is said to be online if the repeater receives data; this indicates that there is a failing segment after the repeater. The technical staff has determined that there is a single faulty segment. To locate and fix it, an expedition is required.

An expedition plan defines how the trip will happen based on the diagnoses that are made along the way. The picture above shows a possible scenario with repeaters (that is, segments). Five possible expedition plans for this case follow:
- Diagnose repeater 2. If it's offline, then diagnose repeater 1 to decide which of the first two segments is the faulty segment. On the contrary, if repeater 2 is online, then diagnose repeater 3 to decide which of the last two segments is failing.
- Diagnose in order repeaters 1, 2, and 3, stopping early when the failing segment is found.
- Diagnose in order repeaters 1, 3, and 2, stopping early when the failing segment is found.
- Diagnose in order repeaters 3, 1, and 2, stopping early when the failing segment is found.
- Diagnose in order repeaters 3, 2, and 1, stopping early when the failing segment is found.
The total cost of an expedition is composed of sailing cost, diving cost, and fixing cost. The sailing cost is proportional to the distance sailed. The diving cost for each dive is proportional to the depth of the repeater. The fixing cost for the failing segment depends on the terrain it is laid across. In our example, the costs of the first-mentioned expedition plan would be as follows:
- If the first segment is failing, the expedition sails to repeater 2, dives, sails back to repeater 1, dives, and repairs the segment. So the sailing cost is , the diving cost is , and the fixing cost is , for a total of .
- If the second segment is failing, the total cost is .
- If the third segment is failing, the total cost is .
- If the fourth segment is failing, the total cost is .
Due to the high affinity between network disruptions and Murphy's Law, the most accurate cost estimation for an expedition plan is the maximum it can reach. That is, we should consider that the failing segment is always the one that makes the expedition have maximum cost. Thus, the estimated cost of the first expedition plan is . Your task is to find the minimum estimated cost among all expedition plans. In our example, the expedition plan that diagnoses in order repeaters 1, 3 and 2 would have total costs of , , , or , depending on the failing segment. This means its estimated cost is , which is the minimum among all expedition plans.
Input
The first line contains an integer () indicating the number of repeaters. The second line contains integers ( for ), where is the cost of sailing between repeaters and . The third line contains integers ( for ), such that is the cost of diving to repeater . The last line contains integers ( for ), where is the cost of fixing the -th segment.
Output
Output a single line with an integer indicating the minimum estimated cost among all expedition plans.