AmazonOA #209
Compute Maximum Scheduled Tasks
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyTwo Pointers
There are n mandatory tasks and n optional tasks, and each task can be done at most once. Each day exactly one mandatory task is scheduled, plus at most one optional task, and their total duration must not exceed H. Find the maximum number of optional tasks completed in n days.
Input
The first line contains n H, the second line the mandatory durations, and the third line the optional durations. 1≤n,H≤200000; all durations are in 1..H.
Output
Output a single integer, the answer.
Example 1
Input:
4 7
4 5 2 4
5 6 3 4
Output:
2
Example 2
Input:
2 2
1 1
1 1
Output:
2
Example 3
Input:
1 3
3
1
Output:
0
Example notes
The answers are 2, 2 and 0; a total exactly equal to the daily limit can be scheduled.
Editorial
Loading solution…