Maximum Capacity Within Budget
You are given two integer arrays costs and capacity, both of length n, where costs[i] represents the purchase cost of the i^th machine and capacity[i] represents its performance capacity.
You are also given an integer budget.
You may select at most two distinct machines such that the total cost of the selected machines is strictly less than budget.
Return the maximum achievable total capacity of the selected machines.
Example 1
Input
costs = [4,8,5,3], capacity = [1,5,2,7], budget = 8Output
8Choose machines 0 and 3 with total cost 7, which is strictly less than 8, for a total capacity of 8.
Example 2
Input
costs = [3,5,7,4], capacity = [2,4,3,6], budget = 7Output
6Choose machine 3 with cost 4, which is strictly less than 7, for a total capacity of 6.
Constraints
- 1 <= n == costs.length == capacity.length <= 10^5
- 1 <= costs[i], capacity[i] <= 10^5
- 1 <= budget <= 2 * 10^5