Maximum Total Number of Orders Fulfilled
Learn this problemProblem statement
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?
Function
solution(D: int[], C: int[], P: long) → intWrite a function:
class Solution { public int solution(int[] D, int[] C, long P); }
that, given two arrays of integers D and C, and a long integer P, returns the maximum total number of orders that can be fulfilled.
Examples
Example 1
D = [5, 11, 1, 3]C = [6, 1, 3, 2]P = 7return = 2Example 2
D = [10, 15, 1]C = [10, 1, 2]P = 3return = 1Example 3
D = [11, 18, 1]C = [9, 18, 8]P = 7return = 0Example 4
D = [1, 4, 2, 5]C = [4, 9, 2, 3]P = 19return = 4Constraints
- 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].
More Microsoft problems
- Authentication SystemOA · Seen Jul 2026
- Binary String Swap TimeOA · Seen Jul 2026
- Minimum Effort Task ScheduleOA · Seen Jul 2026
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026