An array X consists of N integers. The indices of any two elements of the array can be swapped with each other.
Write a program to find the minimum contiguous sum of the elements of the array that is obtained by performing a maximum of K swaps in the array.
(The resulting contiguous sub-array that is selected for the optimal answer should not be empty).
Input format
- First line: T (Number of test cases)
- First line in each test case: N and K
- Second line in each test case: N space-separated integers (denoting the elements of the array X )
Output format
For each test case, print the minimum contiguous sum of the elements that is obtained by performing at most K swaps.
question link: here
p.s. : the question is from a challenge that is over now : )
my approach is to select k smallest elements from the array, but it’s not working…
can anyone share the approach for this question?