K-Capable Model Costs
Learn this problemProblem statement
There are n machine learning models. Model i has cost cost[i] and a two-character string featureAvailability[i]:
"00": supports neither feature."01": supports Feature B only."10": supports Feature A only."11": supports both Feature A and Feature B.
A selected set of models is k-capable if at least k selected models support Feature A and at least k selected models support Feature B. A "11" model counts toward both totals.
For every k from 1 to n, return the minimum total cost needed to choose a k-capable set. If no such set exists, return -1 for that k.
Return a long[] containing the answers for k = 1 through n.
Function
getMinimumModelCosts(cost: int[], featureAvailability: String[]) → long[]Examples
Example 1
cost = [3,2,5,4]featureAvailability = ["10","01","11","00"]return = [5,10,-1,-1]For k = 1, either the dual-feature model or the two single-feature models cost 5. For k = 2, the first three useful models cost 10. Larger values of k are impossible.
Example 2
cost = [8,1,2,6]featureAvailability = ["11","10","01","11"]return = [3,9,17,-1]For k = 1, pair the models costing 1 and 2. For k = 2, also choose the dual-feature model costing 6. For k = 3, all four models are required. The value k = 4 is impossible.
Constraints
- 1 <= n <= 10^5
- 1 <= cost[i] <= 10^9
- featureAvailability[i] is one of "00", "01", "10", or "11".