Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think on Dynamic Programming.
First assume you will be taking the array a and choose some subarray from b
Suppose the DP is DP(pos, state). pos is the current position you are in. state is one of {0,1,2}, where 0 means taking the array a, 1 means we are taking the subarray b, and 2 means we are again taking the array a. We need to handle the transitions carefully.