The Korean Expressway Corporation is planning to expand the road where the volume of traffic is high. In order to expand the road, all the roadside trees nearby the road have to be chopped down.
To do this efficiently, they will rent a logging robot. However, the rental fee is high due to the high production cost, so we want to minimize the time taken by the robot.
The robot can move forward and backward.
The roadside trees (left or right side) can be cut and loaded, which takes 1 minutes per tree.
Trees must be loaded in the order of their cut.
If there are trees on both sides (left and right), without moving, each can be cut and loaded if the above order condition is satisfied.
The robot can load an infinite number of trees.
N.0) is the starting point.N) is the ending point.The first line is an integer N — the length of the road.
The next two lines contain the lengths of the trees at each point from 0 to N:
L — tree lengths on the left side.R — tree lengths on the right side.Print the shortest time (in minutes) that is required to cut down all the trees, starting from the starting point to the ending point.
Example 1:
N = 5
L = 0 3 2 1 0 0
R = 0 3 2 1 0 0
Output: 11 minutesExample 2:
N = 7
L = 0 5 1 5 9 1 5 0
R = 0 0 0 0 0 0 0 0
Output: 23 minutesExample 3:
N = 10
L = 0 7 3 5 7 7 1 0 5 8 0
R = 0 7 7 0 1 0 1 1 0 0 0
Output: 51 minutes