Problem · Array
Maximize Impression Value
Learn this problemProblem statement
You are given n ad impressions. Each impression has a value and a cost (its floor price), and you have a fixed budget.
Select a subset of the impressions whose total cost does not exceed budget. Return the maximum possible sum of their values.
Each impression may be selected at most once.
Function
maximizeImpressionValue(values: int[], costs: int[], budget: int) → longExamples
Example 1
values = [10,40,30,50]costs = [5,4,6,3]budget = 10return = 90Select the second and fourth impressions. Their total cost is 4 + 3 = 7, and their total value is 40 + 50 = 90. No other valid subset has a larger total value.
Constraints
1 <= values.length = costs.length <= 10001 <= budget <= 10^51 <= values[i] <= 10^91 <= costs[i] <= 10^5