You are given n distinct objects, each with a non-negative integer weight. A subset can be any selection of these objects (including the empty subset).
Define the weight of a subset as the sum of weights of the objects in that subset.
Return the k subset weights with the largest sums, sorted in descending order.
w
of length
n
(
w[i] >= 0
), where all objects are distinct.
k
.
k
containing the
k largest subset sums
in
non-increasing
order.
1 <= k <= 2^n
.
If w = [3, 2, 1]:
0, 1, 2, 3, 3, 4, 5, 6
k=4
sums (descending) are:
[6, 5, 4, 3]
1 <= n <= 2e5
(or large enough that enumerating all
2^n
subsets is infeasible)
0 <= w[i] <= 1e9
1 <= k <= min(2^n, 2e5)