
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Sort the rewards array first.
If we decide to apply some rewards, it's always optimal to apply them in order.
The transition is given by: <code>dp[i][j] = dp[i - 1][j − rewardValues[i]]</code> if <code>j − rewardValues[i] < rewardValues[i]</code>.
Note that the dp array is a boolean array. We just need 1 bit per element, so we can use a bitset or something similar. We just need a "stream" of bits and apply bitwise operations to optimize the computations by a constant factor.