3181. Maximum Total Reward Using Operations II
3181. Maximum Total Reward Using Operations II
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 <= 5 * 10^4
1 <= rewardValues[i] <= 5 * 10^4
Hints/Notes
- 2024/04/09
- bitset
- 0x3Fâs solution(checked)
- Weekly Contest 401
Solution
Language: C++
1 | class Solution { |