Ctrl K

The Heavier Share of the Loot

Easy
A crew is splitting its loot: every item has a value, and the values are listed in the array values. You want to claim a set of items whose total value is **strictly greater** than the total value of everything left to the crew. Claim as few items as possible, and among all choices with that smallest number of items, pick the one with the largest total value. It can be shown that the resulting values are uniquely determined. Return the values of the claimed items in non-increasing order.
Example 1
values=[3, 8, 2, 7, 5] → [8, 7]

The total is 25. One item is not enough: 8 < 17. The two most valuable give 8 + 7 = 15 > 10, so that is the answer.

Example 2
values=[6, 6, 6, 6] → [6, 6, 6]

Two sixes give 12, exactly as much as is left, but the share must be strictly larger, so three are needed.

Example 3
values=[50] → [50]
Constraints
  • 1 ≤ len(values) ≤ 500
  • 1 ≤ values[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCake Slices for Guests EasyStrength of the Weaker Partner EasyTriangle From Sticks EasySign Flips for the Largest Sum EasyPack the Backpack Easy
loading Python…
Input
values=[3, 8, 2, 7, 5]
Expected
[8, 7]

Run checks the first 3 tests in your browser. Submit checks all 57 tests on the server, hidden ones included.