Let $A$ and $B$ be two arrays of size $n$ with positive integer values. Let $k$ be a given positive integer.
Design an algorithm to solve the following problem.
For each index $i$ ($1\leq i \leq n$) either select $A[i]$ or $B[i]$ but not both such that the total sum of the picked elements from each of the arrays is at least $k$?
For example $A=[1,2,3,4,5,49]$ and $B=[1,10,10,10,22,12]$, target $k=50$.
Solution
Pick the first and the last elements from A whose sum is 50.
Pick the rest (all but the first and the last elements) from B. That sums up to 52.
So in both Arrays we get a sum at least the target value 50.
Can someone help me to find the algorithm to solve this problem?