Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Reward Using Operations II

Maximum Total Reward Using Operations II asks you to choose unmarked values from an array, adding a value only when it exceeds your current total, to maximize the final reward.

Statement

You are given an integer array rewardValues of size nn.

Initially, your total reward x is 00, and all indices are unmarked. You can perform the following operation any number of times:

  1. Pick an unmarked index i from 00 to n−1n - 1 such that rewardValues[i] > x.

  2. Add rewardValues[i] to your current total reward x (i.e., x = x + rewardValues[i]).

  3. Mark the index i.

Return the maximum total reward x you can achieve by performing the operations optimally.

Constraints:

  • 1≤1 \leq rewardValues.length ≤5×104\leq 5 \times 10^4

  • 1≤1 \leq rewardValues[i] ≤5×104\leq 5 \times 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Reward Using Operations II

Maximum Total Reward Using Operations II asks you to choose unmarked values from an array, adding a value only when it exceeds your current total, to maximize the final reward.

Statement

You are given an integer array rewardValues of size nn.

Initially, your total reward x is 00, and all indices are unmarked. You can perform the following operation any number of times:

  1. Pick an unmarked index i from 00 to n−1n - 1 such that rewardValues[i] > x.

  2. Add rewardValues[i] to your current total reward x (i.e., x = x + rewardValues[i]).

  3. Mark the index i.

Return the maximum total reward x you can achieve by performing the operations optimally.

Constraints:

  • 1≤1 \leq rewardValues.length ≤5×104\leq 5 \times 10^4

  • 1≤1 \leq rewardValues[i] ≤5×104\leq 5 \times 10^4