MicrosoftOA #37
Maximum Total Number of Orders Fulfilled
Estimated EasyJudge-ready
Topics (AI-labelled)Greedy
All orders of closer customers must be fulfilled before any farther customer can be served, and customers at the same distance may be served in any order. Each order can only be delivered in full. Find the maximum number of orders that stock P can fulfill.
Input
The first line contains N P (1≤N≤100000, 0≤P≤10¹⁰), the second line contains N distances D, and the third line contains N demands C (all 1..10⁹).
Output
Output a single integer, the answer.
Example 1
Input:
4 7
5 11 1 3
6 1 3 2
Output:
2
Example 2
Input:
3 3
10 15 1
10 1 2
Output:
1
Example 3
Input:
3 2
1 1 2
5 1 1
Output:
1
Example notes
Example 1: first deliver the orders at distances 1 and 3, using 3+2=5; the next order needs 6, which is not enough, so 2 orders are fulfilled.
Example 2: first deliver the nearest demand of 2, leaving 1; the demand of 10 at distance 10 cannot be delivered, and you cannot skip ahead to 15, so 1 order is fulfilled.
Example 3: at the same distance, deliver the demand of 1 first, leaving 1, which is not enough for the demand of 5; therefore no farther order can be served, and 1 order is fulfilled.
Editorial
Loading solution…