Maximum Total Number of Orders Fulfilled
A technology company announced that a new supply of P monitors would soon be available at their store. There were N orders (numbered from 0 to N-1) placed by customers who wanted to buy those monitors. The K-th order has to be delivered to a location at distance D[K] from the store and is for exactly C[K] monitors.
Now the time has come for the monitors to be delivered. The orders will be fulfilled one by one. To minimize the shipping time, it has been decided that the deliveries will be made in order of increasing distance from the store. If there are many customers at the same distance, they can be processed in any order. Monitors to more distant customers will be delivered only once all orders to customers closer to the store have already been fulfilled.
What is the maximum total number of orders that can be fulfilled?
Write a function:
class Solution { public int solution(int[] D, int[] C, int P); }
that, given two arrays of integers D and C, and an integer P, returns the maximum total number of orders that can be fulfilled.
1Example 1
2Example 2
3Example 3
4Example 4
Constraints
Limits and guarantees your solution can rely on.
- N is an integer within the range [1..100,000].
- Each element of arrays D and C is an integer within the range [1..1,000,000,000].
- P is an integer within the range [0...10,000,000,000].