cswork / OA打开练习工作台

AmazonOA #341

Maximize Secondary Tasks Scheduling

估计中等可在线判题

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

There are n primary tasks and n secondary tasks. Over n days, schedule exactly one primary task each day; each day may also take at most one secondary task, each task can be used only once, and a day's total duration must not exceed limit. Find the maximum number of secondary tasks. If some primary task alone exceeds the limit, return −1 according to this site's no-solution output convention. Zero durations are also judged by whether the total stays within the limit.

输入格式

The first line contains n limit, the second line contains n primary values, and the third line contains n secondary values. On this site 1≤n≤100000, 0≤limit and all durations≤10^9. Inputs with a primary task over the limit are kept, and only the −1 no-solution encoding is added.

输出格式

Output a single integer, the answer.

样例 1

输入:

2 10
1 9
1 9

输出:

2

样例 2

输入:

1 0
0
0

输出:

1

样例 3

输入:

1 2
3
0

输出:

-1

样例说明

The outputs of the three public examples are 2; 1; and -1, checked by independent enumeration or direct simulation.