We are given an array
a and an integer
k. We must make
k modifications to to the array in which replace the element at any index
We have the determine the maximum sum that can be obtained after K such modifications.
Input: A = [2,-3,-1,5,-4], K = 2 Output: 13 Explanation: Choose indices (1, 4) and A becomes [2,3,-1,5,4].
Just like our previous greedy problems, this also has a property that we can observer, which can be greedily used to find the answer.
1. We want the smallest of the negative numbers to become positive.
2. After that we want the smallest element in the array to become negative, if required so that we can get the maximum sum.