3180. Maximum Total Reward Using Operations I
3180. Maximum Total Reward Using Operations I
Description
You are given an integer array rewardValues
of length n
, representing the values of rewards.
Initially, your total reward x
is 0, and all indices are unmarked . You are allowed to perform the following operation any number of times:
- Choose an unmarked index
i
from the range[0, n - 1]
. - If
rewardValues[i]
is greater than your current total rewardx
, then addrewardValues[i]
tox
(i.e.,x = x + rewardValues[i]
), and mark the indexi
.
Return an integer denoting the maximum total reward you can collect by performing the operations optimally.
Example 1:
1 | Input: rewardValues = [1,1,3,3] |
Example 2:
1 | Input: rewardValues = [1,6,4,3,2] |
Constraints:
1 <= rewardValues.length <= 2000
1 <= rewardValues[i] <= 2000
Hints/Notes
- Weekly Contest 401
- dp
Solution
Language: C++
1 | class Solution { |