cswork / OA打开练习工作台

AmazonOA #268

Maximize Secondary Tasks Scheduled

估计中等可在线判题

考点(AI 标注)贪心调度双指针滑窗

n primary tasks are completed over n days, exactly one per day. The total time on each day must not exceed limit; each day can also hold at most one secondary task, and each of the n secondary tasks can be used at most once. Find the maximum number of secondary tasks that can be completed; some secondary tasks may be left unscheduled.

输入格式

The first line contains n limit, the second line primary, and the third line secondary. The original text had no numeric bounds; this site uses 1≤n≤200000, 1≤limit≤10^9, 1≤primary[i]≤limit, 1≤secondary[i]≤10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

2 11
10 1
1 10

输出:

2

样例 2

输入:

2 5
4 4
2 3

输出:

0

样例 3

输入:

3 4
1 2 3
3 2 1

输出:

3

样例说明

The answers are 2, 0 and 3. In the first example the leftover capacities 1 and 10 should be matched with 1 and 10 respectively; the largest leftover must not be wasted on the shortest task first.