MicrosoftOA #37
Maximum Total Number of Orders Fulfilled
估计简单可在线判题
考点(AI 标注)贪心调度
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.
输入格式
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 a single integer, the answer.
样例 1
输入:
4 7
5 11 1 3
6 1 3 2
输出:
2
样例 2
输入:
3 3
10 15 1
10 1 2
输出:
1
样例 3
输入:
3 2
1 1 2
5 1 1
输出:
1
样例说明
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.