nums
in non-increasing order.subsequenceSum
and remainingSum
, to keep track of the sum of the subsequence and the sum of the remaining elements respectively.remainingSum
to the total sum of the array nums
.remainingSum
.
b. Add the element to subsequenceSum
.
c. Add the element to the subsequence list.
d. If subsequenceSum
is greater than remainingSum
, break the loop.