AmazonOA #161
Find Maximum Number of Subjects Passed (AS Intern, but it may apply to other interns)
Estimated EasyJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
Each subject already has answered[i] questions answered correctly, and passing requires at least needed[i]. You may answer at most q more questions correctly in total, distributed among the subjects in any way; maximize the number of subjects passed.
Input
The first line contains n q, the second line contains answered, and the third line contains needed. 1≤n≤100000; 0≤(each element),q≤10^9.
Output
Output a single integer answer.
Example 1
Input:
3 100
24 27 0
51 52 100
Output:
2
Example 2
Input:
2 1
2 4
4 5
Output:
1
Example 3
Input:
2 0
5 2
3 2
Output:
2
Example notes
Example 1: the first two subjects need 27+25=52 questions, so 2 subjects can be passed; all three subjects would need 152 questions, which exceeds the budget. Example 2: add 1 question to the second subject to pass 1 subject. Example 3: both subjects already meet the requirement, so no extra answers are needed and the answer is 2.
Editorial
Loading solution…