Topical
InterviewTime limit1sMemory limit1024 MB
Given knowledge requirements and gains for n modules across k topics, find the maximum number of modules Benson can complete in some order.
Statement
Benson the Rabbit is attending pilot school.
He has modules to complete, numbered from to . There are topics in flying, numbered from to . Benson is new to flying, so his knowledge starts at zero in every topic.
Each module has a knowledge requirement. To complete module , Benson needs at least knowledge in each topic . Completing module gives him more knowledge in each topic .
Formally, let be Benson's knowledge in topic . Initially, for all . He can complete module only if for every topic . After he completes module , increases by for each topic .
Benson may complete the modules in any order, but he may complete each module at most once. Find the maximum number of modules he can complete.
Input
The first line contains two space-separated integers and .
The next lines describe the requirements. The -th of these lines contains space-separated integers .
The following lines describe the gains. The -th of these lines contains space-separated integers .
Output
Print one integer, the maximum number of modules Benson can complete.
Constraints
for all and .