Farm Village
Time limit2sMemory limit512 MB
Each house along a road needs one crop unit and can grow up to two; minimize the total growing cost plus cost of carrying crops between neighbors.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
There is a village along a road. The village has houses, numbered 1 to in order along the road. Each house has a field that can grow up to two units of the crop, and each house needs exactly one unit. The total cost of giving every house one unit of the crop is the sum of the carrying costs and the growing costs.
- Carrying cost: carrying one unit of the crop between house and house costs . The cost is the same in either direction.
- Growing cost: growing one unit of the crop in the field of house costs .
Compute the minimum total cost of supplying one unit of the crop to every house.
Input
The input is a single test case in the following format.
N
d1 d2 ... dN-1
g1 g2 ... gN
The first line contains an integer (), the number of houses. The second line contains integers separated by spaces. The -th integer (, ) is the carrying cost between house and house . The third line contains integers separated by spaces. The -th integer (, ) is the growing cost of the field of house .
Output
Print the minimum cost of supplying one unit of the crop to every house.