Imagine you're a treasure hunter exploring a dungeon filled with reward chests of different values. You start with x = 0 gold coins, and there's a magical rule: you can only open a chest if its value is greater than your current total gold.
Given an integer array rewardValues representing the values of n chests, your goal is to maximize the total reward you can collect. Each chest can only be opened once, and you must choose the order strategically to unlock the highest possible total.
The Challenge: Once you collect a reward, your total increases, which might prevent you from opening smaller chests later. Plan your moves wisely!
Example: With chests [1, 1, 3, 3], you could collect 1 + 3 = 4 coins by opening the first chest (value 1) when x=0, then a chest with value 3 when x=1.
Input & Output
Constraints
- 1 โค rewardValues.length โค 2000
- 1 โค rewardValues[i] โค 2000
- All elements in rewardValues are positive integers
- You can only select a reward if its value is strictly greater than your current total