#3645

Maximum Total from Optimal Activation Order

expert · 1115 · lc medium +32 · 33.1% accepted · 78 likes · top 11%

Description

Two integer arrays value and limit of length n are given. All elements start inactive. To activate element i, the count of currently active elements must be strictly less than limit[i]; activating it adds value[i] to a running total. After each activation, if the active count becomes x, any element j with limit[j] <= x is permanently deactivated. Choose the activation order to maximize the total. Return that maximum.

Code

1
2
3