Optimize Creative Effects for Mobile
As a senior engineer at Adobe, you're tasked with optimizing the performance of a new feature for a mobile version of a creative application (e.g., Photoshop Express, Lightroom Mobile). This feature allows users to apply multiple enhancement effects (filters) to an image. Each effect consumes a certain amount of processing power (CPU/GPU cycles) and contributes a specific 'visual impact score' to the final image.
The challenge is that mobile devices have a finite processing budget to ensure a smooth, responsive user experience. You need to select a subset of available effects that maximizes the total visual impact score without exceeding the device's processing budget. This problem is crucial for balancing feature richness with application performance on resource-constrained platforms.
Implement the function optimizeEffects that takes three parameters:
processingCosts: An array of numbers, where processingCosts[i] represents the processing power consumed by the i-th effect.visualImpacts: An array of numbers, where visualImpacts[i] represents the visual impact score provided by the i-th effect.maxBudget: A number representing the total processing power available.Your function should return the maximum possible total visual impact score that can be achieved by selecting a subset of effects, such that their combined processing cost does not exceed maxBudget. Each effect can be used at most once.
processingCosts: number[], visualImpacts: number[], maxBudget: number
processingCosts: An array of non-negative integers representing the cost of each effect.visualImpacts: An array of non-negative integers representing the impact of each effect.maxBudget: A non-negative integer representing the maximum allowed total processing cost.number
i-th element in processingCosts corresponds to the i-th element in visualImpacts.maxBudget, the function should return 0.Examples
Example 1
Input:
processingCosts = [2, 3, 4], visualImpacts = [3, 4, 5], maxBudget = 5
Output:
7
Note:
With a budget of 5:
Example 2
Input:
processingCosts = [10, 20], visualImpacts = [5, 8], maxBudget = 5
Output:
0
Note:
The maxBudget is 5. Both effects have processing costs (10 and 20) that exceed the budget individually. Therefore, no effects can be chosen, resulting in a total visual impact of 0.
Example 3
Input:
processingCosts = [1, 2, 3, 4, 5], visualImpacts = [10, 20, 30, 40, 50], maxBudget = 7
Output:
70
Note:
With a budget of 7:
Constraints
1 <= N <= 500, where N is the number of effects (i.e., processingCosts.length).processingCosts.length === visualImpacts.length.0 <= processingCosts[i] <= 1000 for all i.0 <= visualImpacts[i] <= 1000 for all i.0 <= maxBudget <= 10000.Loading editor...