Input: arr[] = {2, 4, 5, 8}, min[] = {1, 4, 5, 5}, K = 3
Output: 18
Explanation:
Choose the elements in the following order:
Step 1: Choose element 8. Now, S = 8 and arr[] = {-1, 4, 5} and min[] = {1, 4, 5}
Step 2: Choose element 5. Now, S = 8 + 5 = 13 and arr[] = {-1, 4} and min[] = {1, 4}
Step 3: Choose element 5. Now, S = 8 + 5 + 4 = 17 and arr[] = {-1} and min[] = {1}
Step 4: Choose element -1, but -1 < min[0]. Therefore, choose 1.
Hence, S = 8 + 5 + 4 + 1 = 18.
Input: arr[] = {3, 5, 2, 1}, min[] = {3, 2, 1, 3}, K = 2
Output: 12
Explanation:
Choose the elements in the following order:
Step 1: Choose element 5. Now, S = 5 and arr[] = {3, 0, 1} and min[] = {3, 1, 3}
Step 2: Choose element 3. Now, S = 5 + 3 = 8 and arr[] = {0, 1} and min[] = {1, 3}
Step 3: Choose element 3 from min[]. Now, S = 5 + 3 + 3 = 11 and arr[] = {0} and min[] = {1}
Step 4: Choose element 1 from min[].
Hence, S = 5 + 3 + 3 + 1 = 12.