You are given two integer arrays energy and threshold, each of length n.
Initially, all reactors are inactive. You can activate them in any order, but under specific conditions:
• To activate a reactor at index i, the number of currently active reactors must be strictly less than threshold[i].
• When you activate reactor i, it contributes energy[i] to your total energy output.
• After each activation, if the number of currently active reactors becomes x, then all reactors j where threshold[j] <= x become permanently inactive, even if they are currently active.
Your task is to determine the maximum total energy that can be achieved through an optimal activation sequence.
Input: energy = [6, 2, 9] threshold = [3, 1, 2]
Output: 17
Input: energy = [5, 10, 3] threshold = [1, 1, 1]
Output: 18
Accepted:
Submission: