3181. Maximum Total Reward Using Operations II Hard
1/**
2 * [3181] Maximum Total Reward Using Operations II
3 *
4 * You are given an integer array rewardValues of length n, representing the values of rewards.
5 * Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times:
6 *
7 * Choose an unmarked index i from the range [0, n - 1].
8 * If rewardValues[i] is greater than your current total reward x, then add rewardValues[i] to x (i.e., x = x + rewardValues[i]), and mark the index i.
9 *
10 * Return an integer denoting the maximum total reward you can collect by performing the operations optimally.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">rewardValues = [1,1,3,3]</span>
15 * Output: <span class="example-io">4</span>
16 * Explanation:
17 * During the operations, we can choose to mark the indices 0 and 2 in order, and the total reward will be 4, which is the maximum.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">rewardValues = [1,6,4,3,2]</span>
22 * Output: <span class="example-io">11</span>
23 * Explanation:
24 * Mark the indices 0, 2, and 1 in order. The total reward will then be 11, which is the maximum.
25 * </div>
26 *
27 * Constraints:
28 *
29 * 1 <= rewardValues.length <= 5 * 10^4
30 * 1 <= rewardValues[i] <= 5 * 10^4
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/maximum-total-reward-using-operations-ii/
36// discuss: https://leetcode.com/problems/maximum-total-reward-using-operations-ii/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn max_total_reward(reward_values: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_3181() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.