If there are multiple solutions, then find the subsequence with the maximum total sum. Also, assume that there will be a unique solution.
The first line contains an integer ‘T’ denoting the number of test cases. Then each test case follows.
The first input line of each test case contains an integer ‘N’ denoting the number of elements in the given array/list.
The second input line of each test case contains ‘N’ space-separated integers denoting the elements of the “ARR”.
For each test case, print the space-separated integers denoting the elements of the desired subsequence in non-increasing order.
Print the output of each test case in a separate line.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= T <= 50
1 <= N <= 10000
1 <= ARR[i] <= 10000
Where ARR[i] denotes the i-th element of the given array/list.
Time limit: 1 sec
The key idea of this approach is to sort the elements of the given array/list in non-increasing order. Since we are looking for the subsequence having a minimum length such that the sum of its elements is strictly greater than the sum of the rest of the elements, we will choose elements from the front of the sorted array/list greedily. This will ensure that we are selecting the minimum possible elements for getting any sum.
Now, consider the following steps: